block-lambda revival

Marc Harter wavded at gmail.com
Thu Jun 23 14:01:58 PDT 2011


Peter Michaux encouraged me to write my thoughts on es-discuss so here I am.

Out of the various new function syntaxes proposed ( ->, #, {||} ) I
have really taken a liking to the block-lambda revival strawman.  I
think in general they all address similar wishes (e.g. implicit
return, this, shorter). I prefer the block-lambda because of some use
cases:

let a = [1,2,3,4];
let b = a.reduce((a,b) -> a + b) // didn't see an example for this one
assuming this is how it looks
let b = a.reduce {|a,b| a + b} // less cluttery, fn bound by braces,
couple characters less to type

Self executing function expressions

(-> {
  // multi-line
}())

{||
  // multi-line -- i'm assuming there wouldn't need to be parens
around the whole thing because block lambdas are expressions not
statements (is this the case with arrow?)
}()

I like block-lambda because:

  1. From my understanding braces aren't going away, lets just embrace
them (use them as part of the syntax)
  2. Arrow gets too bulky with braces (although worked good for CoffeeScript)
  3. Seems to be terse yet clear
  4. Encloses the function

It may be nice to have side by side comparisons of the different
proposals doing the same operation.

Anyway, my 2 cents.  Thanks!

-- 
Marc (@wavded)


More information about the es-discuss mailing list