RosettaCodeData/Task/Named-parameters/Tcl/named-parameters-1.tcl
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

11 lines
419 B
Tcl
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

proc example args {
# Set the defaults
array set opts {-foo 0 -bar 1 -grill "hamburger"}
# Merge in the values from the caller
array set opts $args
# Use the arguments
return "foo is $opts(-foo), bar is $opts(-bar), and grill is $opts(-grill)"
}
# Note that -foo is omitted and -grill precedes -bar
example -grill "lamb kebab" -bar 3.14
# => foo is 0, bar is 3.14, and grill is lamb kebab