<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sun Feb 12 11:46:09 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='288'>
<header><title>Allow &quot;args&quot; Anywhere in Procedure Formal Arguments</title><author address="mailto:peter.spjuth@space.se">Peter Spjuth</author><author address="mailto:avl@logic.at">Andreas Leitgeb</author><author address="mailto:peter.spjuth@gmail.com">Peter Spjuth</author><status type='project' state='draft' tclversion="8.7" vote='prior'>$Revision: 1.10 $</status><history></history><created day='3' month='oct' year='2006' /><keyword>Tcl proc</keyword></header>
<abstract>This TIP proposes to make <emph style="italic">args</emph> have its special meaning as a formal <emph style="bold">proc</emph>edure argument anywhere in the argument list.</abstract>
<body><section title="Rationale">
<para>Many commands, specially many of Tcl&apos;s built in commands, have their variadic arguments in the beginning of the argument list and their required arguments at the end. An example is [<emph style="bold">lsearch</emph> ?<emph style="italic">options</emph>? <emph style="italic">list string</emph>].</para>
<para>Writing tcl procedures in that style is currently a bit cumbersome since you need to do you own argument counting and assignment to variables from &quot;args&quot;.</para>
<para>If &quot;args&quot; had its special meaning at any location in the argument list, it would help with such a task, and it would make things more consistent.</para>
<para>To get simple semantics, optional arguments are not allowed after &quot;args&quot;. Optional arguments that precede &quot;args&quot; will be handled as before. This TIP does not, as of now, specify defaulted arguments directly preceding non-defaulte ones. This should be addressed in a separate TIP.</para>
</section>
<section title="Specification">
<para>At most one proc argument may be named &quot;args&quot; and can be anywhere in the argument list. Arguments after &quot;args&quot; may not be optional. Arguments are assigned in the following order:</para>
<enumerate><item.e index='1'><para>Assign arguments right of &quot;args&quot; from the right.</para></item.e><item.e index='2'><para>Assign arguments left of &quot;args&quot; from the left. Handling of defaulted parameters preceding &quot;args&quot; remains as it was (but disregarding the non-defaulted ones after &quot;args&quot;).</para></item.e><item.e index='3'><para>Remaining arguments are assigned to &quot;args&quot;.</para></item.e></enumerate>
</section>
<section title="Compatiblity">
<para>Currently &quot;args&quot; is allowed anywhere in the argument list, and becomes a normal variable if not last. Most scripts probably don&apos;t use this since it would be rather confusing, but it might exist.</para>
<para>All such occurrances would need to be fixed.</para>
<para>Detecting such scripts in an automated way would be simple and fixing them is trivial.</para>
</section>
<section title="Examples">
<para>New style:</para>
<verbatim><vline encoding='base64'>cHJvYyBsZ3Vya2Ege2FyZ3MgbGlzdCBpdGVtfSB7</vline><vline encoding='base64'>ICAgIGFycmF5IHNldCBvcHRzIHstYXBhIDEgLWJlcGEgIiIgLWNlcGEgMH0=</vline><vline encoding='base64'>ICAgIGZvcmVhY2gge2FyZyB2YWx9ICRhcmdzIHs=</vline><vline encoding='base64'>ICAgICAgICBzZXQgb3B0cyhbcHJlZml4IG1hdGNoIHstYXBhIC1iZXBhIC1jZXBhfSAkYXJnXSkgJHZhbA==</vline><vline encoding='base64'>ICAgIH0=</vline><vline encoding='base64'>ICAgICMgRG8gcmVhbCBzdHVmZg==</vline><vline encoding='base64'>fQ==</vline></verbatim>
<para>Old style:</para>
<verbatim><vline encoding='base64'>cHJvYyBsZ3Vya2Ege2FyZ3N9IHs=</vline><vline encoding='base64'>ICAgIGlmIHtbbGxlbmd0aCAkYXJnc10gPCAyfSB7</vline><vline encoding='base64'>ICAgICAgICByZXR1cm4gLWNvZGUgZXJyb3IgIndyb25nICMgYXJnczogc2hvdWxkIGJlIFwibGd1cmthID9hcmdzPyBsaXN0IGl0ZW1cIiI=</vline><vline encoding='base64'>ICAgIH0=</vline><vline encoding='base64'>ICAgIHNldCBpdGVtIFtsaW5kZXggJGFyZ3MgZW5kXQ==</vline><vline encoding='base64'>ICAgIHNldCBsaXN0IFtsaW5kZXggJGFyZ3MgZW5kLTFd</vline><vline encoding='base64'>ICAgIHNldCBhcmdzIFtscmFuZ2UgJGFyZ3MgMCBlbmQtMl0=</vline><vline encoding='base64'></vline><vline encoding='base64'>ICAgIGFycmF5IHNldCBvcHRzIHstYXBhIDEgLWJlcGEgIiIgLWNlcGEgMH0=</vline><vline encoding='base64'>ICAgIGZvcmVhY2gge2FyZyB2YWx9ICRhcmdzIHs=</vline><vline encoding='base64'>ICAgICAgICBzZXQgb3B0cyhbcHJlZml4IG1hdGNoIHstYXBhIC1iZXBhIC1jZXBhfSAkYXJnXSkgJHZhbA==</vline><vline encoding='base64'>ICAgIH0=</vline><vline encoding='base64'>ICAgICMgRG8gcmVhbCBzdHVmZg==</vline><vline encoding='base64'>IH0=</vline></verbatim>
<verbatim><vline encoding='base64'>cHJvYyB4IHthIGFyZ3MgYn0geyBwdXRzICJhPSRhLCBhcmdzPSRhcmdzLCBiPSRiIiB9</vline></verbatim>
<verbatim><vline encoding='base64'>eCAxIDIgIDsjIC0+ICAgYT0xLCBhcmdzPSwgYj0y</vline></verbatim>
<verbatim><vline encoding='base64'>eCAxIDIgMyA7IyAtPiAgYT0xLCBhcmdzPTIsIGI9Mw==</vline></verbatim>
<verbatim><vline encoding='base64'>eCAxIDsjIC0+IGVycm9yOiB3cm9uZyAjIGFyZ3M6IHNob3VsZCBiZSAieCBhID9hcmdzPyBiIg==</vline></verbatim>
<verbatim><vline encoding='base64'>cHJvYyB5IHthIHtiIHh9IGFyZ3MgY30geyAuLi4gfQ==</vline></verbatim>
<verbatim><vline encoding='base64'>eSAxIDIgMyA7IyAgIGE9MSBiPTIgYz0zICBhcmdzIGlzIGVtcHR5</vline></verbatim>
<verbatim><vline encoding='base64'>cHJvYyB6IHthIHtiIHh9IGMgYXJnc30geyAuLi4gfQ==</vline></verbatim>
<verbatim><vline encoding='base64'>eiAxIDIgIDsjIC0+IGVycm9yOiB3cm9uZyAjIGFyZ3M6IHNob3VsZCBiZSAieiBhID9iPyBjIC4uLiI=</vline></verbatim>
<para>To change &quot;z&quot; is not covered by this TIP.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

