Expression closures - use-cases for shortcut lambda syntax(blocks)
Dave Herman
dherman at ccs.neu.edu
Mon Mar 19 13:43:54 PDT 2007
> This is a trick question! We already have function expressions with a
> 'function' head and a '{...}' body. Dropping the 'return' and braces as
> a *convenience*.
Not a trick question -- of course we already have functions that *are*
expressions; the question is whether all the syntactic forms of
functions (i.e., both function declarations and function expressions)
have a variant where the *body* is an expression.
It's precisely this convenience I'm talking about. In fact, when writing
in a functional style, this convenience adds up pretty quickly. Try
writing a curried function with "return" and curlies -- it's painful,
*especially* because of the sneaky requirement that return can't be
followed by a newline!
function f(x) {
return function (y) {
return function (z) {
return x + y + z;
}
}
}
vs.
f(x) => (y) => (z) => (x + y + z)
or
function f(x) (y) => (z) => (x + y + z)
I didn't quite follow your summary. Indulge my OCD and let me be
painfully explicit. :) Here are all the options I think we're talking
about, individually labelled (a) through (f). (Ignoring some irrelevant
details like named function expressions.)
function-expression
::= "function" id? "(" formals ")" block (a)
| "function" id? "(" formals ")" expression (b)
| "function" id? "(" formals ")" "=>" expression (c)
| "(" formals ")" "=>" expression (d)
function-declaration
::= "function" id "(" formals ")" block (e)
| "function" id "(" formals" ")" expression (f)
| "function" id "(" formals" ")" "=>" expression (g)
| id "(" formals ")" "=>" expression (h)
expression ::= ... | function-expression
declaration ::= ... | function-declaration
I'm in favor of allowing (a), (c), (d), (e), and (g). I think that was
Tucker's proposal just now.
Dave
More information about the Es4-discuss
mailing list