Function Syntax

Brendan Eich brendan at
Thu May 12 14:25:50 PDT 2011

On May 12, 2011, at 1:06 PM, Brendan Eich wrote:

> On May 12, 2011, at 10:55 AM, Brendan Eich wrote:
>> Ruby is far from simple, btw. Check out
>> and the wikipedia page it references.
>> Looks like but not lambda can return from its caller.
> From it should be clear I was missing the "block" target. Blocks are syntactically restricted to being downward funargs. Only if reified as Procs do they potentially escape to be called later when their lexical parent method could have already returned.
> IOW, blocks are restricted to being downward-funargs by syntax at their expression site, and by default in the callee (without the & before the corresponding formal parameter).

To say a bit more about this, here's a demo of the downward-only-funarg nature of blocks passed as extra trailing arguments, with no matching &parameters:

def say
    puts yield "world"

def say_hello
    say {|x| "hello #{x}" }


The output is "hello world" of course, but Ruby's yield calls the block without it escaping as a reified Proc that could be invoked later, after the downward flow. Neat!

(Rubyists, please correct anything wrong here.)

I'm not suggesting we copy any of this, just passing along my Ruby-n00b knowledge. 

> When we considered lambdas (the "Allen's lambda syntax proposal" thread from late 2008 to early 2009), we did not try to confine them syntactically to actual parameter lists. Did we miss a key restriction or feature of Ruby? I'm not sure, I'm too much a Ruby n00b.

If blocks could not escape to be called after their enclosing function had returned, then we would overcome the objection raised last time, articulated best by Maciej:

But Ruby went all the way, allowing a block to grow into a Proc and outlive the method in which the block was expressed. I expect similar "ecological pressures" to apply if we added blocks only as downward-funargs.

Plus, we'd still want shorter function syntax, not just blocks as downward-only funargs (however nice for map, forEach, etc.).

I will write up a block strawman, to give it a fair shake along side

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list