Even simpler lambdas

François REMY fremycompany_pub at yahoo.fr
Tue Apr 17 12:52:50 PDT 2012

I kinda like it. My preferred being:

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

BTW, to respond to @TabAtkins, I know by experience that a very large amount 
of lambdas have 'a', 'b', 'c', 'x', 'y' and 'z' as argument names, because 
lambdas are short and have an obvious use. In fact, many times, typing the 
argument names is a pain. When you really need arguments name, it's 
generally because the code is more complex, or longer. In those particular 
cases, you can still do that:

    arr.map(return do {
        let currentElement = $0;
        let currentIndex = $1;

even if in such cases, I would strongly advocate the use of a true function 
(question of taste).

-----Message d'origine----- 
From: Peter van der Zee
Sent: Tuesday, April 17, 2012 11:33 AM
To: es-discuss
Subject: Even simpler lambdas

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]+'

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
es-discuss mailing list
es-discuss at mozilla.org

More information about the es-discuss mailing list