Russell Leggett wrote:
Thanks for throwing out alternative syntaxes. We should keep beating
on this anvil, shorter function syntax is well worth it. But we need
a non-GLR parsing procedure that rejects ambiguous grammars.
So here's my pitch - I've been thinking over a lot of the different
syntaxes that have been passed around, and I've got a combination that
might just work:
I know it's just bikeshedding, but do you need the -> arrow (it is
better visually)? You can as well take arrowless approach but putting :
before every parameter (as I suggested):
// ':' is the clue that this is the start of a short function
coll.map(:x -> x*x) //function(x){ return x*x;}
coll.map(:x x*x)
// even short functions can be named
coll.filter(when: x -> x%2==1) //function when(x){ return x%2==1;}
coll.filter(when :x x%2==1)
// multiple parameters, and if the function needs a full function body
coll.forEach(:x, i -> {
if(i%2 === 0){
console.log(x + " is " + even);
}else{
console.log(x + " is " + odd);
}
});
coll.forEach(:x, :i {
if(i%2 === 0){
console.log(x + " is " + even);
}else{
console.log(x + " is " + odd);
}
});
// the names can be an asset in more complicated callback situations
when(promise,
ok: result -> doSomething(result),
error: e -> handleError(e)
);
when(promise,
ok :result doSomething(result),
error :e handleError(e)
);
//if no parameters or name, can drop the ':'
$("#other").click(->$("#target").click());
Ah, here is only problem... the arrow does it nicely when there is no
parameter. This could work:
$("#other").click(: $("#target").click());
and the system is changed so that only first param is colonized ;-)
so previous two-param example would be
coll.forEach(:x, i {
if(i%2 === 0){
console.log(x + " is " + even);
}else{
console.log(x + " is " + odd);
}
});
I think this should be easy to parse, and I feel like using : keeps it
from seeming too foreign.
The rationale for arrowless one was to make trivial ones (where the
clutter is most visible) as short as possible. :x x*x is one example.
- Russ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss