I've went through discussion and pointed pages.

David, I'm pretty sure you know why I've ask this. Saw your YUIConf talk and 
that 2 lines slide simply scared me :)

Comprehensions in sense of arrays [x*y for x of .. for y of ..] with array as a 
result is pretty clear, on the other hand — everything is expression in (), and 
my gut (hi Doug) told me any possible thing, but not an object. That's why my 
first thought was about {}.

>From readability point of view if generator comprehension returns object it 
>should be in {}, if array — [], actual value or function expression — () // IMO

>From grammar point of view — {} overloading is a big problem, once we'll do it 
>for the first time — we'll continue to put features and this is dead end.

Probably it's better to not use () comprehension at all?
Kind of a way to avoid misunderstanding and safe {} for literals and blocks 
only.

Anton.

P.S. 
>    var o = { [f(x)]: 12 };        // object literal with property name 
> computed from f(x)
I really need this feature for a while :)
 
>    var g = { [f(x)] for x of a }; // generator producing a sequence of 
> singleton arrays containing f(x)

this kind of syntax probably should not be implemented ever


On Nov 30, 2011, at 7:45 PM, David Herman wrote:

> On Nov 30, 2011, at 7:14 AM, Anton V. Yacenko wrote:
> 
>> It's interesting to me why () syntax returns object, and why not {}.
> 
> I assume you're talking about generator expressions, which have the syntax of 
> array comprehensions but using parentheses as their outer delimiter. The idea 
> originally came from Python, which uses parentheses for generator expressions.
> 
> Using {} is an interesting idea, but it could be tricky to fit that into the 
> grammar, because of the overlap with object literals. Brendan has 
> experimented with the idea of allowing overlap between different {} forms in 
> other contexts:
> 
>    http://wiki.ecmascript.org/doku.php?id=strawman:block_vs_object_literal
> 
> In another discussion about do-expressions:
> 
>    http://wiki.ecmascript.org/doku.php?id=strawman:do_expressions
> 
> we talked about the possibility of allowing block statements as expressions:
> 
>    var g = { let x = f(); x * x };
> 
> and Allen Wirfs-Brock raised objections that allowing overlap between object 
> literals and objects whose contents can be expressions will be a problem for 
> human readers, even if formally unambiguous:
> 
>    https://mail.mozilla.org/pipermail/es-discuss/2011-November/018257.html
> 
> This issue will get worse as we work on extending the grammar of object 
> literals, for example to allow computed property names in square brackets. In 
> the context of generator expressions, this would lead to subtle differences 
> like:
> 
>    var o = { [f(x)]: 12 };        // object literal with property name 
> computed from f(x)
>    var g = { [f(x)] for x of a }; // generator producing a sequence of 
> singleton arrays containing f(x)
> 
> Put differently: we already overload the { } syntax for block statements and 
> object literals, and we use the context to disambiguate. Overloading them 
> further, especially within the same context, would lead to visual confusion.
> 
> Dave
> 

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to