logical-assignment operators

John Cowan cowan at ccil.org
Mon Feb 12 18:00:39 PST 2007

Brendan Eich scripsit:

> > (This will not work in languages where 0 is false,
> > like C and Perl.)
> '' is false in Perl, so this worksforme in Perl:
> $ perl
> my $x;
> $x &&= $x + 5;
> print "$x\n";

Yes, but when $x is 0, it remains 0.

> One pill that we spat out along with these, perhaps it was the only  
> poison: ^^ (and ^^= if ^^ is there). Does anyone have a use-case for  
> value-preserving ^^? We didn't think so when TG1 last considered  
> these oddments from Waldemar's draft js2/es4 proposals.

It's good for handling mutually exclusive options.  If you must specify
either alpha or bravo, then alpha ^^ bravo will be alpha if alpha
was specified, bravo if bravo was specified, and "true" if something is

You are a child of the universe no less         John Cowan
than the trees and all other acyclic            http://www.ccil.org/~cowan
graphs; you have a right to be here.            cowan at ccil.org
  --DeXiderata by Sean McGrath

More information about the Es4-discuss mailing list