Received: Sat, 3 Apr 2004 15:26:46 +0900
And lo, Nicholas wrote:

> While were on the subject, what is technically the difference between some 
> block, such as { |n| 1+n }, and the corresponding lambda { |n| 1+n }, or 
> more specifically, how does the interpreter treat them differently?  Also, 
> could I assign a lambda to a variable as I would in scheme to create a 
> function?

They're the same thing. The following two are identical

myproc = lambda { |n| 1+n }
mymethod("5",lambda)

mymethod("5") { |n| 1+n }

You could then call
myproc.call("4") #-> 5

So to continue with the opcode hash example
op[0x05] = lambda { |addr| ... }
op[0x05].call(address)

the 'lambda' is needed to let ruby know it's defining a Proc object.

c = { |n| 1+n } - doesn't really make sense.

'proc' is an alias for lambda, but I believe it's to be phased out because of proc/Proc confusin. and lambda is really just "Proc.new"

c = Proc.new { |n| 1+n }

These blocks, with 'yield,' are among my favorite things about ruby. =).

- Greg