Re: lambda... again



slebetman@xxxxxxxxx wrote:
....
OTOH since variables are locally scoped writing tcl code in pure
lambdas is going to be annoying:

set something {{} {
global do_something print ;# must "import" all lambdas before
using :-(
$do_something here
$print Done!
}}

set do_something {{x} {
global print ;# typing global all the time quickly gets annoying
$print "doing something: $x"
}}

set print {x {puts "$x\n"}}

$something

You don't have to store lambdas in variables, you can also [interp alias] them:

interp alias {} do_something {} apply {{..} {...}}

Although, of course, if you are doing this then it is best to just use a regular named procedure. The most likely use of a lambda is when it is passed either to or from a procedure as an argument/return value, so no importing would be needed.

-- Neil
.