Existential operator (was: ||= is much needed?)

John Tamplin jat at google.com
Thu Jun 21 08:29:48 PDT 2012


On Thu, Jun 21, 2012 at 11:23 AM, Brendan Eich <brendan at mozilla.org> wrote:

> John Tamplin wrote:
>
>> So do you have to do it by treating the ?. operator as a standalone?
>>
> Not sure what you mean here -- "standalone ?" (with an English-langauge ?
> implied after in your sentence? ;-)?
>
> Or something else that amounts to a concealed Reference or Nil-value-proxy
> expression?
>
> Just talking spec here: as Allen mentioned, ECMA-262 specifies semantics
> by evaluating productions in a mostly-LR(1) grammar, so member and call
> expressions (left-associative) have to result in some kind of
> (spec-internal or language-external) value.
>
> Thus foo?.bar.baz.quux is really (((foo?.bar).baz).quux).


Yes, and I am suggesting during parsing it gets treated as:

(((foo?.bar)?.baz)?.quux)

because we saw a ?. operator earlier in the expression.  That way you don't
have to get the Coffeescript behavior by introducing some fake object or a
MaybeReference, and you just implement the ?. operator as always returning
the LHS if it is null/undef.


> Indeed one can translate when parsing. CoffeeScript does this, with some
> separate passes for its other purposes (implicitly declared variables,
> indentation-based block structure, etc.).
>
> The ES specs can't do this, though, not without a total rewrite.


I realize it would be changes, but then so would adding a MaybeReference.
 Just thought I would bring it up.

-- 
John A. Tamplin
Software Engineer (GWT), Google
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120621/23da1ab3/attachment-0001.html>


More information about the es-discuss mailing list