(Almost) everything is expression

Andreas Rossberg rossberg at google.com
Fri Nov 11 04:18:32 PST 2011


On 11 November 2011 12:48, François REMY <fremycompany_pub at yahoo.fr> wrote:
> I think you strongly underestimate the "distinction" problem. It's *not*
> possible to make any difference between the "foo" statement and the "print"
> statement of your sample, from the compiler point of view. Why would the
> "foo" statement be the one chosen as a return value for the "if" block? It's
> completelty unclear to me.

JavaScript already has the notion of "completion value" of a statement
sequence, which defines exactly that. It is used to determine the
result of eval calls. Unfortunately, the completion value is currently
determined dynamically, but there is a proposal for correcting that
behaviour, see <http://wiki.ecmascript.org/doku.php?id=harmony:completion_reform>.

Using this to define implicit return values of blocks or functions was
one idea behind that proposal. Effectively, this just generalizes the
comma operator (which is redundant in the same way ?: is).

/Andreas


More information about the es-discuss mailing list