Array comprehensions shorter syntax (?)
Dmitry A. Soshnikov
dmitry.soshnikov at gmail.com
Tue May 31 23:20:24 PDT 2011
On 01.06.2011 3:06, Waldemar Horwat wrote:
> On 05/29/11 07:00, Dmitry A. Soshnikov wrote:
>> Yeah, and ES also supports them. It's called a generator expression;
>> in this proposal it would look like:
>>
>> let squares = (x * x | x < data, x > 5);
>
> Ahem, that's already a parenthesized comma expression with operands
>
Yes, true (haha, this one is even a correct ES3 expression :D, and not
only with the typo `< data`, but with the arrow: `<- data`). Though, I
just was excited with arrow functions so proposed Erlang's list
comprehensions (Erlang also uses arrows for functions btw, though,
that's said, it uses two pipes [X*X || X <- Data, X > 5]). Regarding
comma, I though, perhaps it would be possible to treat it correctly in
this context -- well, no means no.
P.S.: another question I have -- is it worth and makes sense to raise a
topic on considering/standardizing the pattern matching (Dave's
proposal)?
http://wiki.ecmascript.org/doku.php?id=strawman:pattern_matching Brendan
mentioned on Twitter that it's "too late" (?), but IMO this proposal is
much more interesting and needed for the lang than e.g. WeakMaps (which
of course are also useful stuff, but not so powerful addition as
pattern-matching would).
Dmitry.
> x * x | x < data
>
> and
>
> x > 5.
>
> Remember that | is a perfectly fine binary operator.
>
> Waldemar
>
> PS. Block lambdas don't suffer from this problem because neither |
> nor || is a valid unary prefix operator, so they can be made
> syntactically unambiguous.
More information about the es-discuss
mailing list