See also:
MGS [2003/09/09] - Note that info level 0 does not return values for optional arguments (if they have not been specified):
proc foo {bar {baz NULL}} {
puts "info level 0 = \[[info level 0]\]"
}
# example1
foo abc def
# example2
foo abcprints:info level 0 = [foo abc def] info level 0 = [foo abc]DGP Correct. [info level $level] returns the substituted list of values that make up the actual command as evaluated.To get values for non-specified default arguments, you have to do quite a bit more work using info args, info default.This proc will print out info for all args in the calling proc (note: does not handle being called from global level).
proc arginfo {} {
set proc [lindex [info level -1] 0]
set which [uplevel [list namespace which -command $proc]]
puts "proc \[$which\]"
set i -1
foreach arg [info args $which] {
incr i
set value [uplevel [list set $arg]]
if { [info default $which $arg def] } {
puts " arg\[$i\] \[$arg\] = \[$value\] default = \[$def\]"
} else {
puts " arg\[$i\] \[$arg\] = \[$value\]"
}
}
}
# test code
proc test {foo {"bar baz" "BAR BAZ"}} {
arginfo
}
test abc
test abc defwhich prints the output:proc [::test] arg[0] [foo] = [abc] arg[1] [bar baz] = [BAR BAZ] default = [BAR BAZ] proc [::test] arg[0] [foo] = [abc] arg[1] [bar baz] = [def] default = [BAR BAZ]
