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 <gazhe...@gmail.com <mailto:gazhe...@gmail.com>> wrote:

    On 11 November 2011 15:33, Mark S. Miller <erig...@google.com
    <mailto:erig...@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@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to