On Nov 11, 2011, at 3:48 AM, François REMY wrote:
> I think you strongly underestimate the "distinction" problem. ... It's
> completelty unclear to me. If there's no way to tell what the "return
> statement" of the block is, there's no way to implement your proposal.
It's actually quite easy to implement Dmitry's proposal, because it's already
specified by the ECMAScript semantics! All statements can produce completion
values. You can test this yourself: take any statement, quote it as a string,
and put it in eval, and you'll get a value (if it doesn't loop infinitely, exit
the program, or throw an exception, of course).
As Andreas said, there's a subtler issue of whether there's a simple structure
to value-producing substatements, and there's a few problematic cases, but
there's already a plan to clean that up at
http://wiki.ecmascript.org/doku.php?id=harmony:completion_reform
But that's mostly a secondary issue, to keep things more regular and to be more
compatible with tail calls.
To answer your specific example:
> let a = if (foo) {
> print('a is foo');
> foo;
> } else {
> // do some longer stuff
> };
>
> How do you know "foo" is an expression that should be assigned to "a" and
> that "print('a...')" is not?
Because the then-branch of the if is a block, and the completion value of a
block is specified in ECMAScript to be the last completion value produced by
its body statements.
Dave
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss