logical-assignment operators

Brendan Eich brendan at mozilla.org
Mon Feb 12 13:21:31 PST 2007


On Feb 12, 2007, at 12:51 PM, John Cowan wrote:

> Steve Yegge scripsit:
>> Hi folks,
>
>> A little bird told me that TG1 may have dropped support for the
>> assignment operators &&=, ||=, ^^= due to lack of popular demand  
>> and/or
>> compelling use cases.
>>
>> If so, I thought I'd lobby to get at least ||= added back in.
>
> I agree, and I think there is a use case for &&= as well.  Suppose
> that x is either an integer or null.  Then
>
> 	x &&= x + 5;
>
> will increment x by 5 unless it is null, in which case it will be
> left alone.  (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";

Is that what you meant?

BTW, I'm in favor of &&= and ||= now that I think for three seconds  
about the || use cases I know, which really wanted ||= all along.

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.

/be




More information about the Es4-discuss mailing list