Re: lambda... again



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

.



Relevant Pages

  • Re: NULL = NULL not working
    ... >>I have a proc that can specify a price range if its passed in. ... Think of NULL as an unknown value. ...
    (microsoft.public.sqlserver.mseq)
  • Re: Execution of external commands
    ... eval $inp ... lets try (assumed the [unknown] proc exists as set up in the interactive ... will look for a proc named "grep". ...
    (comp.lang.tcl)
  • User domainautodl not recognized by AutoDL
    ... specified the user name and password in the DSN AutoDL. ... Proc: webWhoAmI ... connection. ...
    (microsoft.public.exchange2000.applications)
  • Re: lambda... again
    ... The disadvantage is that calling a lambda is different from calling a ... regular proc. ... proc unknown args $what\n ...
    (comp.lang.tcl)
  • Re: is possible to have a proc within a proc?
    ... for a proc to have a proc within itself? ... recursivity and local functions. ... namespaces and lambdas. ...
    (comp.lang.tcl)