declaring variants/subports in loops and loop variables
Gustaf Neumann
neumann at wu.ac.at
Thu Dec 8 13:26:40 CET 2016
Am 07.12.16 um 18:04 schrieb Joshua Root:
>
> This is almost exactly the same situation as:
>
> foreach foo {bar baz} {
> proc p_$foo {} {
> puts $foo
> }
> }
> p_bar
> p_baz
you probably want the variable "foo" being substituted in the body of the
dynamically defined procs:
% foreach foo {bar baz} {
proc p_$foo {} [subst {
puts "$foo"
}]
}
% p_bar
% p_baz
One might check the body of the dynamically defined proc via
"info body /procname/". This reveals that the quotes around
the argument of "puts" are necessary for cases, when e.g. the
value of the variable "foo" contains spaces.
% info body p_bar
puts "bar"
%
When the body contains content, which should not be substituted
(per default, "subst" performs variable, command and
backslash substitutions) use the proper flags for "subst"
or backslashes. e.g.:
foreach foo {bar baz} {
proc p_$foo {} [subst -nocommands {
puts "$foo"
return [string repeat "$foo " 10]
}]
}
p_bar
p_baz
Hope, this helps
-g
More information about the macports-dev
mailing list