Re: lambda... again



On Oct 23, 6:48 am, yuriy.ers...@xxxxxxxxx wrote:
Yes, I have read about ithttp://wiki.tcl.tk/519http://wiki.tcl.tk/10782

Why didn't anyone use this obvious variant?

proc lambda {p b} {
set name [list lambda $p $b]
if {[info procs $name] eq ""} {
proc $name $p $b
}
return $name

}

General lambda use cases work well:

% [lambda {s1 s2} {puts "s1=$s1 s2=$s2"}] asd cvb
s1=asd s2=cvb

% set aaa [lambda {s1 s2} {puts "s1=$s1 s2=$s2"}]
lambda {s1 s2} {puts "s1=$s1 s2=$s2"}
% $aaa q w
s1=q s2=w


Personally I think the [apply] method that we now have in 8.5 is the
way to go. Lambdas are after all merely values. So there is no reason
to treat a lambda as anything other than a string until you want to
use it as a function. So:

# In tcl a lambda is simply a string:
set aaa {{s1 s2} {puts "s1=$s1 s2=$s2"}}

# Only when you want to use it does it need special treatment:
apply $aaa q w

The advantage is that unlike the proc work-arounds the apply method
has all the advantages of regular variables: local scope, passable as
first class citizens etc.

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..... ;-)

.



Relevant Pages

  • Re: Whats wrong with lambda and class
    ... If the lambda is being coerced, it isn't being honest about it: ... The idea that it has to do with yield is basically right, ... class Proc. ... the methodnotation to send a Proc instance to ...
    (comp.lang.ruby)
  • Re: When are lambdas needed?
    ... is that lambda treats return, next, and break a little bit differently. ... It's actually a difference between lambda and proc (which are ... lambdas are invoked using the same semantics as a message send. ... Lambdas act like methods in that: ...
    (comp.lang.ruby)
  • Re: "nameless" procedures
    ... namespace eval lambda { ... proc lambda { ...
    (comp.lang.tcl)
  • Re: Assigning a block to a variable in Ruby
    ... 2003 Matz agreed that 'proc' would be deprecated in favor of 'lambda', because having something called proc and something called Proc.new that weren't the same was confusing. ... They give you the warning sometimes, ...
    (comp.lang.ruby)
  • Re: When are lambdas needed?
    ... is that lambda treats return, next, and break a little bit differently. ... It's actually a difference between lambda and proc (which are ... lambdas are invoked using the same semantics as a message send. ... Lambdas act like methods in that: ...
    (comp.lang.ruby)