> SUMMARY
> C<$var ?= $x : $y> as a shortcut for C<$var = $var ? $x : $y>.
> 
> 
> DETAILS
> We have ||=, +=, -=, etc.  These shortcuts (I'm sure there's some fancy
> linguistic term for them) save us a few keystrokes and clean up the code.
> 
> So, concerning C<? :>, I find myself doing this type of thing a lot:
>     $var = $var ? 1 : 0;
> How 'bout a shortcut for that, something like this:
>     $var ?= 1 : 0;

[Modulo already-pointed-out Perl6 operator spelling changes.]

I agree that it would seem right to have a ??= assignment operator,
since a bunch of other operators have it too.  If there's no added
complexity to the Perl parser in introducing this operator, there's
probably no argument against it.

But . . .  (metaphysical waffle begins)

What argument is there *for* including a ??= operator?  The whole point
in the assignment operators +=, ||=, //=, etc. is that they modify the
*existing value* of the variable.  That is, the final result of the
variable usually reflects in some way the original value.

The example above:
  $var ??= 1 :: 0;
would end up with either 1 or 0 in $var, pretty much irrespective of the
value that was in $var.  At least these:
  $var ||= 1;
  $var &&= 0;
leave the possibility that the original value of $var is retained.  A
??= operator wouldn't be in the spirit of the other assignment
operators.

(Well, yes, there's:
  $var ??= $var :: $foo;
and the like, but those can equally be expressed in terms of operators
we already have, for instance:
  $var ||= $foo;
)

I guess what I'm saying is that someone needs to provide a real-world,
non-contrived, example showing ??= in use.  This example would need to
demonstrate that using ||= or &&= or its relatives would be less
comprehensible.

(metaphysical waffle ends)

I can't imagine ever needing such an operator.  Perhaps that's hubris
(in which case, prove me wrong with an example), or perhaps it's because
there *is* no need for such an operator (in which case all it'll be is
another footnote in the Camel nth edition).  Which is it?

-- 
Debbie Pickett http://www.csse.monash.edu.au/~debbiep [EMAIL PROTECTED]
         "You gotta bat your eyes - like this." - _The Little Mermaid_

Reply via email to