Re: lambda... again
- From: "slebetman@xxxxxxxxx" <slebetman@xxxxxxxxx>
- Date: Tue, 23 Oct 2007 01:00:37 -0700
On Oct 23, 3:32 pm, suchenwi <richard.suchenwirth-
bauersa...@xxxxxxxxxxx> wrote:
On 23 Okt., 03:22, "slebet...@xxxxxxxxx" <slebet...@xxxxxxxxx> wrote:
The disadvantage is that calling a lambda is different from calling a
regular proc (you need to prepend apply to it). Now... if someone
feels like modifying [unknown] so that lambdas can be called like a
proc.....
Oh, that's easily done:
% proc know what {
if ![info complete $what] {error "incomplete command(s) $what"}
proc unknown args $what\n[info body unknown]
}
% know {
if {[llength [lindex $args 0]]==2} {return [eval [linsert $args 0
apply]]}
}
% set try {{a b} {expr {$a * $b}}}
{a b} {expr {$a * $b}}
% $try 7 6
42
It just conflicts with spaces in command names, so don't do both... :^)
HA! Now that we have this we can TRULY treat everything as a string.
Proc is no longer necessary. Just store everything in variables!
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
.
- Follow-Ups:
- Re: lambda... again
- From: Neil Madden
- Re: lambda... again
- From: Yuriy Ershov
- Re: lambda... again
- From: suchenwi
- Re: lambda... again
- References:
- lambda... again
- From: yuriy . ershov
- Re: lambda... again
- From: slebetman@xxxxxxxxx
- Re: lambda... again
- From: suchenwi
- lambda... again
- Prev by Date: Re: Call by Reference
- Next by Date: Re: lambda... again
- Previous by thread: Re: lambda... again
- Next by thread: Re: lambda... again
- Index(es):
Relevant Pages
|
|