Different semantics should have different-looking syntax

Peter Michaux petermichaux at gmail.com
Sat Jun 4 19:24:45 PDT 2011


On Sat, May 21, 2011 at 12:37 PM, Brendan Eich <brendan at mozilla.com> wrote:
> For http://wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival I have written up the Ruby-inspired {|x| x * x} syntax.
>
> Alternatives (ignoring keyword issues) that look more like function syntax (Peter's suggestion of lambda (x) { x * x }, e.g.) seem worse in this light: block lambdas do follow the correspondence principle, which is novel to JS with its C statements for control effects heritage.
>
> In this light, the use of | | to bracket formal parameters seems better than anything using (...) {...}. This is not an overriding concern, but it seems worth mentioning. We want block-lambdas or any such TCP-pure new thing to have syntax that says "look! something new here".

I don't think this idea of needing different syntax for different
semantics is a strong point in favour of the {||} syntax. ECMAScript
programmers are already accustomed to the keyword(){} syntax template
and have *no* trouble understanding the difference between the
following two bits of code and what return means in each.

    if(a){return a;}

    function(a){return a;}


> And, since the strawman builds on block syntax, we want the new form to have syntax that "looks like a block", in which you'd expect TCP purity for break, continue, return, |this|, and arguments.

Lambdas are useful for more than just blocks in control structures. I
don't think that use should be the sole force behind choosing the
syntax.

Peter


More information about the es-discuss mailing list