Optional Chaining (aka Existential Operator, Null Propagation)

John Lenz concavelenz at gmail.com
Thu Feb 4 16:47:48 UTC 2016


On Wed, Feb 3, 2016 at 2:41 PM, Claude Pache <claude.pache at gmail.com> wrote:

>
> > Le 3 févr. 2016 à 20:56, John Lenz <concavelenz at gmail.com> a écrit :
> >
> > Can you reference something as to why the more obvious operators are
> problematic?
> >
> > ?.
>
> That one (that I've used) must work, with the simple lookahead I've put in
> the lexical grammar, in order to continue to parse `x?.3:0` as today.
>
> > ?[]
> > ?()
>
> For those it is difficult for the parser to easily (i.e. quickly, without
> trying and backtracking code of arbitrary length) distinguish from the
> conditional operator, as in: `x ?(y - 2) + 3 : 0` Also, the difference of
> precedence level between the two operators makes the use of a cover grammar
> (I think) impossible.
>

Waldemar's example makes the problem obvious but I think we could do use,
which I think is preferable to the proposed:

.?
(?)
[?]



>
> > ?:
>
> I'm not sure what that one should be used for. (If you mean the Elvis
> operator, it's out of the scope of the proposal.
>

yes, I meant the equivalent to:

x ?: value
x == null ? x : value



> —Claude
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160204/931235c8/attachment.html>


More information about the es-discuss mailing list