(Almost) everything is expression
Dmitry Soshnikov
dmitry.soshnikov at gmail.com
Fri Nov 11 10:25:58 PST 2011
On 11.11.2011 21:13, David Herman wrote:
> On Nov 11, 2011, at 8:19 AM, Mark S. Miller wrote:
>
>> On Fri, Nov 11, 2011 at 7:40 AM, gaz Heyes <gazheyes at gmail.com
>> <mailto:gazheyes at gmail.com>> wrote:
>>
>> On 11 November 2011 15:33, Mark S. Miller <erights at google.com
>> <mailto:erights at google.com>> wrote:
>>
>> let a = ({
>>
>> print('doing stuff');
>> 100;
>> });
>>
>>
>> How do you know the difference between a blank block statement
>> and a object literal? Surely it becomes an expression once an
>> assignment occurs anyway.
>>
>>
>> Doh! Sorry, I completely mis-thought that. Nevermind.
>
> Your idea of mandatory parens is still valid (if, IMO, a bit
> unsatisfyingly verbose) for most statement forms. It's only the
> block-statement-expression that doesn't work. Hence my do-expressions:
>
> http://wiki.ecmascript.org/doku.php?id=strawman:do_expressions
>
> or Brendan's subtly-disambiguated-block-statement-expressions:
>
> http://wiki.ecmascript.org/doku.php?id=strawman:block_vs_object_literal
>
> If Brendan's idea can be made to work, and it's not too confusing, I'm
> pretty sure I'd prefer it over do-expressions. You could simply write:
>
> let a = {
> print('doing stuff');
> 100
> };
>
If we write so in e.g. if-expression (which actually uses the same
*block*), then by logic we should write the same in a simple (and the
same) *block*:
// conditional evaluation of `a`
let a = if (true) { 10 } else { 20 }
// unconditional evaluation of `a`
let a = {10}
(BTW, everyone already now may test it -- as Dave noted, you may use
`eval` to get the completion type of a statement; moreover, you may
write a simple parser which just replaces all such expressions with
`eval`s -- not for production sure, but for tests: let a = eval('if
(true) {10} else {20}'); console.log(a) -- 10)
OTOH, if there will be unresolvable (?) issues with grammar, etc, we may
of course adopt a special syntax of eval'ing such simple blocks,
unfortunately regardless, that e.g. in `if` which uses the same block we
may write it easily and directly.
> How gorgeous is that?
>
It's normal and consistent with other blocks, I'd say.
Dmitry.
> But I suspect as we work on evolving the syntax of object literals,
> it'll get harder to keep them disambiguated. For example, is this:
>
> let a = {
> foo(x)
> {
> alert(x)
> }
> }
>
> ...equivalent to this?
>
> let a = {
> foo: function(x)
> {
> alert(x);
> }
> };
>
> ...or this?
>
> let a = {
> foo(x);
> {
> alert(x);
> }
> };
>
> So I just don't know if it's feasible.
>
> Dave
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111111/2d36df4a/attachment.html>
More information about the es-discuss
mailing list