suggestion: mapping symbolic infix ops to binary functions

Brendan Eich brendan at
Wed Jul 25 01:31:59 PDT 2012

Claus Reinke wrote:
> but would not be sufficient
> - for combinations of short-circuiting and assignment '??='
>    lhs ??= default_value;  // lhs = lhs ?? default_value

No, sufficiently powerful macros can handle these too, without References.

> At least, I can't think of a way to avoid reevaluating the left
> hand side operand - if I assign it to a temporary variable, it
> no longer is a valid left hand side for an assignment.

The trick is to specialize as all competitive JS engines do today to 
avoid references:

   id op= val  ~~~>  id = id op val op= val  ~~~> do { let $t = obj; $ = $ op val }
   obj[x] op= val  ~~~> do { let $t = obj, $u = x; $t[$u] = $t[$u] op val }

assuming op handles its own short-circuiting (or not). Longer macro 
expansion using && || ?: or if-else as needed.

The macro system just needs to be able to specialize on the various 
legal lvalue special forms.


More information about the es-discuss mailing list