Reputation:
I have a question about the following proc:
proc setDefault {{nampspaceList "ALL"}} {
if {$nampspaceList == "ALL"} {
set nampspaceList "namespace1 namespace2 namespace3"
}
foreach ns $nampspaceList {
append ns "::setDefault"
$ns
}
}
The appended ns is "::setDefaultnamespace1namespace2namespace3", but what is the meaning of &ns in foreach loop, everytime append a namespace, it will print out the result once?
Upvotes: 0
Views: 134
Reputation: 12978
The foreach
loop in your procedure is looping through the list held in the variable nampspaceList
, and for each item in the list it is creating a command by appending ::setDefault
to it.
The line $ns
then attempts to execute that command.
Upvotes: 3
Reputation: 170
Ehm, no, the final value of ns after running the foreach loop is "[lindex $nampspaceList end]::setDefault", because in each iteration ns is set with each item in the list $nampspaceList.
You could check that by adding a few puts in the middle of the code.
For instance calling it with: setDefault {ns1 ns2 ns3}
will have ns set to ns1::setDefault
(after the append of "::setDefault"), ns2::setDefault
and ns3::setDefault
.
Upvotes: 1