<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 08:51:13 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='65'>
<header><title>Enhanced [info args]</title><author address="mailto:glennj@nortelnetworks.com">Glenn Jackman</author><author address="mailto:dgp@users.sf.net">Don Porter</author><author address="mailto:glennj@ncf.ca">Glenn Jackman</author><status type='project' state='rejected' tclversion="8.5" vote='after'>$Revision: 1.6 $</status><history></history><created day='18' month='sep' year='2001' /></header>
<abstract>This TIP proposes a new subcommand to the [info] command be added that would return the list of arguments, together with any default values in the same format as the <emph style="italic">args</emph> parameter to the [proc] command.</abstract>
<body><section title="Introduction">
<para>The [proc] man page defines <emph style="italic">args</emph> as:</para>
<quote>... the formal arguments to the procedure. It consists of a list, possibly empty, each of whose elements specifies one argument. Each argument specifier is also a list with either one or two fields. If there is only a single field in the specifier then it is the name of the argument; if there are two fields, then the first is the argument name and the second is its default value.</quote>
<para>Suppose we define a procedure like this:</para>
<verbatim><vline encoding='base64'>ICAgICAgIHByb2MgdGVzdCB7b25lIHt0d28gMn0ge3RocmVlIHszIDQgNX19IGFyZ3N9IHtyZXR1cm59</vline></verbatim>
<para>We want to determine the formal arguments for this procedure. We want some method to return the list:</para>
<verbatim><vline encoding='base64'>ICAgICAgIG9uZSB7dHdvIDJ9IHt0aHJlZSB7MyA0IDV9fSBhcmdz</vline></verbatim>
<para>[info args] fails us because it does not return default values, only the list of argument names {one two three args}.</para>
<para>The [info default] command exists, and does partially what we want. However [info default] only operates on a single argument. To determine the complete list of arguments with default values, we must iterate over the arguments returned by [info args]. We would define a procedure like:</para>
<verbatim><vline encoding='base64'>ICAgICAgIHByb2MgaW5mb19hcmdzX3dpdGhfZGVmYXVsdHMge3Byb2NuYW1lfSB7</vline><vline encoding='base64'>ICAgICAgICAgICBzZXQgYXJnc3BlYyBbbGlzdF0=</vline><vline encoding='base64'>ICAgICAgICAgICAjIFtpbmZvIGFyZ3NdIHRocm93cyBhbiBlcnJvciBpZiAkcHJvY25hbWUgaXMgbm90IGEgcHJvY2VkdXJlLg==</vline><vline encoding='base64'>ICAgICAgICAgICBmb3JlYWNoIGFyZyBbaW5mbyBhcmdzICRwcm9jbmFtZV0gew==</vline><vline encoding='base64'>ICAgICAgICAgICAgICAgaWYge1tpbmZvIGRlZmF1bHQgJHByb2NuYW1lICRhcmcgdmFsdWVdfSB7</vline><vline encoding='base64'>ICAgICAgICAgICAgICAgICAgIGxhcHBlbmQgYXJnc3BlYyBbbGlzdCAkYXJnICR2YWx1ZV0=</vline><vline encoding='base64'>ICAgICAgICAgICAgICAgfSBlbHNlIHs=</vline><vline encoding='base64'>ICAgICAgICAgICAgICAgICAgIGxhcHBlbmQgYXJnc3BlYyAkYXJn</vline><vline encoding='base64'>ICAgICAgICAgICAgICAgfQ==</vline><vline encoding='base64'>ICAgICAgICAgICB9</vline><vline encoding='base64'>ICAgICAgICAgICByZXR1cm4gJGFyZ3NwZWM=</vline><vline encoding='base64'>ICAgICAgIH0=</vline><vline encoding='base64'>ICAgICAgIGluZm9fYXJnc193aXRoX2RlZmF1bHRzIHRlc3QgIDsjID09PiByZXR1cm5zIHtvbmUge3R3byAyfSB7dGhyZWUgezMgNCA1fX0gYXJnc30=</vline></verbatim>
<para>A more sophisticated scripted solution is to overload the [info] command itself, as described in the Wiki at <url ref="http://wiki.tcl.tk/wrappingCommands"/></para>
<para>It would be much more convenient to be able to rely on the [info] command itself to return the desired information, particularly since it <emph style="italic">almost</emph> does what we want already.</para>
<para><emph style="italic">This topic was originally raised in the <url ref="news:comp.lang.tcl"/> newsgroup in the thread <url ref="http://groups.google.com/groups?th=4b0d5dba85d2c160"/></emph></para>
</section>
<section title="Specification">
<para>Add [info formalargs] to the set of subcommands for Tcl&apos;s built-in [info] command, with syntax:</para>
<verbatim><vline encoding='base64'>IGluZm8gZm9ybWFsYXJncyAkcHJvY05hbWU=</vline></verbatim>
<para>This command will raise an error if <emph style="italic">$procName</emph> is not the name of a proc. Otherwise, it will return a list of formal arguments of the named proc, along with their default values, if any, in a format suitable for passing to the [proc] command as a second argument.</para>
</section>
<section title="Rationale">
<para>With the goal of maintaining backwards compatibility in mind, two possibilities arise: adding a new switch to the existing [info args] command, and adding a completely new subcommand to [info].</para>
<para>Adding a switch to [info args] may break backwards compatibility. If we use the syntax [info args <emph style="italic">?-withdefaults? procname</emph>], there may be trouble with existing scripts containing a procedure named &quot;-withdefaults&quot;. The syntax [info args <emph style="italic">procname ?-withdefaults?</emph>] is completely backwards compatible. However, among Tcl commands that take subcommands, there is currently some inconsistency as to where switches should appear. [clock] subcommands place these options after required parameters. [namespace] and [package] subcommands place these options before required parameters. Some [file] subcommands put them before, some after. Currently, no [info] subcommands take switches.</para>
<para>Rather than compound to this inconsistency, creating a new [info] subcommand feels cleaner. Possible names include:</para>
<describe><item.d name='argspec, arglist, args_with_defaults'><para>These all collide with the &quot;arg&quot;, &quot;ar&quot;, &quot;a&quot; shorthands for [info args <emph style="italic">procname</emph>]. And <emph style="italic">args_with_defaults</emph> is just *way* too ugly.</para></item.d><item.d name='formalargs, fullargs'><para>Either of these could be used. This collides with the &quot;f&quot; shorthand for [info functions]</para></item.d><item.d name='parameters'><para>This collides with the &quot;pa&quot; shorthand for [info patchlevel]</para></item.d><item.d name='prototype'><para>This collides with the &quot;pro&quot; and &quot;pr&quot; shorthands for [info procs <emph style="italic">?pattern?</emph>]</para></item.d><item.d name='signature'><para>This could be used, as it does not collide with any shorthand for either [info script] or [info sharedlibextension].</para></item.d></describe>
<para>The term &quot;signature&quot; has meaning in the Java and C++ worlds: the function name and its arguments together comprise the signature. The purpose of this TIP is to return only the arguments with any defaults, so to avoid any potential confusion I will rule out &quot;signature&quot;.</para>
<para>Of the remaining possibilities, my choice would be &quot;formalargs&quot;. The term &quot;formal arguments&quot; is used in the [proc] man page. &quot;formalargs&quot; also incorporates the word &quot;args&quot;, indicating a relationship to [info args].</para>
</section>
<section title="Reference Implementation">
<para>Refer to the submitted patch, which implements an subcommand named [info fullargs], at: <url ref="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=461635&amp;group_id=10894&amp;atid=310894"/></para>
</section>
<section title="Reasons for Rejection">
<para>Those voting against this proposal believed that since the desired functionality is already possible with a short script of just a few Tcl commands, it would be unnecessary bloat to add another subcommand. Some also pointed to <tipref type="text" tip="112"/> as another approach to letting people extend Tcl built-in commands with their own custom subcommands.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

