Even simpler lambdas

Peter van der Zee ecma at qfox.nl
Tue Apr 17 02:33:46 PDT 2012


Why can't lambda's be a simple case of a lexically scoped `return`
keyword with any arguments implicitly defined and accessible through a
predefined identifier/keyword (much like `arguments` works now)?

arr.map(return '<'+arguments[0]+'
class="'+this.getClassName(arguments[1])+'"/>');

arr.map(return '<'+$0+' class="'+this.getClassName($1)+'"/>');

arr.map(return '<'+$[0]+' class="'+this.getClassName($[1])+'"/>');

Or maybe the hash sign...

arr.map(return '<'+#0+' class="'+this.getClassName(#1)+'"/>');

It's going to be hard to come up with a solid grammar for allowing
statements this way though (return {foo:bar} would be an objlit, not a
block with label). Is that why it's not being considered?

You could work around that by restricting grammar for `return` and
`{`. So `return{` would always start a block. I'm aware that this is
also currently valid syntax for returning an object literal, but I
think objections over introducing more restricted grammar rules trumps
that anyways... :)

Anyways, I like it because it's short, consise, and it feels very
intuitive to me. We'd basically overload the return keyword much like
the function keyword is right now. As a statement it'd remain the
same. As an expression it becomes shorthand notation for a function.

- peter


More information about the es-discuss mailing list