Replies: 2 comments 2 replies
-
So you need to understand that lambda returns a local proc name (even though the proc is created in the local namespace). This is just the same as proc does. If you want to export that name so that it can be used outside the namespace, you need to use namespace canon. For example.
Outputs:
While you can use $x inside the namespace, you need to use namepace canon to return a name that can be resolved globally. Compare:
Again we need to use namespace canon (or just return "a::p") because plain "p" won't resolve into the "a" namespace. |
Beta Was this translation helpful? Give feedback.
-
Thanks for taking time out for that explanation, makes sense. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm new to tcl and jim, so I may have this ass backwards, but i find the lambda and namespace confusing
I have a proc in global namespace
proc scenario2 {scenario} {
set subs [subst [readFile scenarios/$scenario/config.tcl]]
puts "loaded scenario $scenario"
eval "set l "$subs
lambda {args} &l {
dict getdef $l {*}$args "undefined: $args"
}
}
i can do
set $s [scenario2 live]
and then
$s blah
to retrieve an arbitrary property from the dict - this is what i expect.
But when I put same function in namespace utils
set $s [::utils::scenario2 live]
I found the answer to be
::utils::$s blah
but I expected the lambda to be in the global namespace or in the namespace of the caller.
If this is the normal behaviour, maybe some extra documentation would be useful as it's
not an intuitive default (for me anyway :)).
Apart from that jim is awesome!
Cheers.
Beta Was this translation helpful? Give feedback.
All reactions