[email protected] <
[email protected]> wrote:
Having
#--------------
proc uno { {param1 x} {param2 y} } {
dos $param1 $param2
}
proc dos { { param1 {} } {param2 {} } } {
puts "dos (1 $param1) (2 $param2)"
}
#----------------------
if we run
uno w z
uno
uno w
uno {} z
we get
dos (1 w) (2 z)
dos (1 x) (2 y)
dos (1 w) (2 y)
dos (1 ) (2 z)
Then, how, in the last case, we get "x" in the first parameter if the parameter sent is "empty"?
Empty string is not "missing entirely". The "use default" mechanism
for procs works by assiging all actual proc parameters (and {} is an
actual parameter in your case above) first, then using the default
values for any parameters which do not have an actual value given them
in the command invocation.
I.e., this: "uno {} z" is a call to uno with two parameters, {} and z,
so the defaults for 'uno' never trigger (two actual parameters, two
slots in the proc definition).
Only your second and third uno call trigger usage of uno's default
values, because there are zero actual parameters (second call) or only
one actual parameter (third call, which then uses the default for only
param2).
This exact outcome is what is being described in the proc man page by
this sentence:
Arguments with default values that are followed by non-defaulted
arguments become de-facto required arguments, though this may
change in a future version of Tcl; portable code should ensure
that all optional arguments come after all required arguments.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)