Allow "args" Anywhere in Procedure Formal ArgumentsPeter SpjuthAndreas LeitgebPeter Spjuth$Revision: 1.14 $Tcl proc
This TIP proposes to make args have its special meaning as a formal procedure argument anywhere in the argument list.
Many commands, specially many of Tcl'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 [lsearch ?options? list string].
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 "args".
If "args" 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.
To get simple semantics, optional arguments are not allowed after "args". Optional arguments that precede "args" 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.
At most one proc argument may be named "args" and can be anywhere in the argument list. Arguments after "args" may not be optional. Arguments are assigned in the following order:
Assign arguments right of "args" from the right.Assign arguments left of "args" from the left. Handling of defaulted parameters preceding "args" remains as it was (but disregarding the non-defaulted ones after "args").Remaining arguments are assigned to "args".
Currently "args" is allowed anywhere in the argument list, and becomes a normal variable if not last. Most scripts probably don't use this since it would be rather confusing, but it might exist.
All such occurrances would need to be fixed.
Detecting such scripts in an automated way would be simple and fixing them is trivial.
New style:
cHJvYyBsZ3Vya2Ege2FyZ3MgbGlzdCBpdGVtfSB7ICAgIGFycmF5IHNldCBvcHRzIHstYXBhIDEgLWJlcGEgIiIgLWNlcGEgMH0=ICAgIGZvcmVhY2gge2FyZyB2YWx9ICRhcmdzIHs=ICAgICAgICBzZXQgb3B0cyhbcHJlZml4IG1hdGNoIHstYXBhIC1iZXBhIC1jZXBhfSAkYXJnXSkgJHZhbA==ICAgIH0=ICAgICMgRG8gcmVhbCBzdHVmZg==fQ==
Old style:
cHJvYyBsZ3Vya2Ege2FyZ3N9IHs=ICAgIGlmIHtbbGxlbmd0aCAkYXJnc10gPCAyfSB7ICAgICAgICByZXR1cm4gLWNvZGUgZXJyb3IgIndyb25nICMgYXJnczogc2hvdWxkIGJlIFwibGd1cmthID9hcmdzPyBsaXN0IGl0ZW1cIiI=ICAgIH0=ICAgIHNldCBpdGVtIFtsaW5kZXggJGFyZ3MgZW5kXQ==ICAgIHNldCBsaXN0IFtsaW5kZXggJGFyZ3MgZW5kLTFdICAgIHNldCBhcmdzIFtscmFuZ2UgJGFyZ3MgMCBlbmQtMl0=ICAgIGFycmF5IHNldCBvcHRzIHstYXBhIDEgLWJlcGEgIiIgLWNlcGEgMH0=ICAgIGZvcmVhY2gge2FyZyB2YWx9ICRhcmdzIHs=ICAgICAgICBzZXQgb3B0cyhbcHJlZml4IG1hdGNoIHstYXBhIC1iZXBhIC1jZXBhfSAkYXJnXSkgJHZhbA==ICAgIH0=ICAgICMgRG8gcmVhbCBzdHVmZg==IH0=
cHJvYyB4IHthIGFyZ3MgYn0geyBwdXRzICJhPSRhLCBhcmdzPSRhcmdzLCBiPSRiIiB9
eCAxIDIgIDsjIC0+ICAgYT0xLCBhcmdzPSwgYj0y
eCAxIDIgMyA7IyAtPiAgYT0xLCBhcmdzPTIsIGI9Mw==
eCAxIDsjIC0+IGVycm9yOiB3cm9uZyAjIGFyZ3M6IHNob3VsZCBiZSAieCBhID9hcmdzPyBiIg==
cHJvYyB5IHthIHtiIHh9IGFyZ3MgY30geyAuLi4gfQ==
eSAxIDIgMyA7IyAgIGE9MSBiPTIgYz0zICBhcmdzIGlzIGVtcHR5
cHJvYyB6IHthIHtiIHh9IGMgYXJnc30geyAuLi4gfQ==
eiAxIDIgIDsjIC0+IGVycm9yOiB3cm9uZyAjIGFyZ3M6IHNob3VsZCBiZSAieiBhID9iPyBjIC4uLiI=
To change "z" is not covered by this TIP.
This document has been placed in the public domain.