Given this proc:
proc foo {{aa "a"} {bb "b"} cc} {
echo $cc
}
Is it possible to call proc foo
and only pass a value for cc
? Also, is it possible to pass a value to cc
explicitly by name?
Everything I see suggests that all arguments must be passed by position.
I would do something like Tk does:
proc foo {cc args} {
# following will error if $args is an odd-length list
array set optional [list -aa "default a" -bb "default b" {*}$args]
set aa $optional(-aa)
set bb $optional(-bb)
puts "aa: $aa"
puts "bb: $bb"
puts "cc: $cc"
}
then
% foo
wrong # args: should be "foo cc ..."
% foo bar
aa: default a
bb: default b
cc: bar
% foo bar -bb hello -aa world
aa: world
bb: hello
cc: bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With