I think it's a good summary of current state of the art. Personally, I'm
all-in with "do(args){}" syntax because it's the syntax that best fit (my)
intuition a well as the current ES syntax (both of a function and of a
block). The arrow syntax is ackward and requires you to read upto the arrow
to distinguish an argument list from a partenthized expression.
Also, I share your reasoning with "fn". It should just either be an alias
for 'function' or either be different enough. Otherwhise, it should not
exist (to avoid creating confusion). Yet, I still think it is a valuable
proposal. Maybe some random idea that just fuzzed in my brain: What about
having it working a bit like the Function constructor, done the right way?
var square = fn(x,x*x); // would desugar to function(x) { return x*x; }
'fn(' + <argument-list> + ',' + <expression-statement> +')'
We could even make it default in strict mode because the compiler can know
at compile time if a variable named 'fn' is defined or not (in which case
that variable would override the 'fn' constructor), or can't the compiler
know that?
BTW, if we are still going to make 'fn' optionnal, I have one small
question: wouldn't it better to allow functions without introductory keyword
instead? If it's optionnal, it's up to the developer that uses it to make
sure his code is compatible, which seems fine to me.
-----Message d'origine-----
From: Axel Rauschmayer
Sent: Sunday, March 11, 2012 12:20 PM
To: es-discuss
Subject: Callable values: trying to summarize
== Arrow syntax ==
The nicest proposal I have seen has been written by David Herman:
https://gist.github.com/2011902
== More traditional solution ==
1. Short notation for non-TCP functions: use fn; enables one to abbreviate
"function" as "fn" [1]. Optional, not sure if that’s a good idea: Implicit
return of completion value and lexical `this`.
For example:
use fn;
arr.map(fn (x) { x * x });
2. Block lambdas for TCP-adhering callable blocks with lexical `this`, which
previously seemed like the main contender. As a TCP-adhering syntactic
alternative to block lambdas, Allen mentioned the following on Twitter:
do (args) { ... }
Open question: fn and function behaving differently seems like a bad idea,
because then things are less consistent. But then you have to wonder if fn
is really worth the trouble for only saving 6 characters.
[1] https://twitter.com/awbjs/status/178792012215091200
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss