[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] @a ||= (1, 2);



Ronald Kimball writes:
> @a ||= (1, 2);
> 
> This is a compile-time error.
> 
> Should it be legal code?  Justify your position.

It would be nice for it to be legal code, for analogy with $a ||=
$ENV{A} and such things.  I don't think it would surprise anybody: if
@a is (), it would set it to (1, 2), and otherwise it would do
nothing.

On the other hand, making it consistent would mean that suddenly ||
would be a list operator, breaking lots of existing code that expects
|| to provide a scalar context.  (Worse, most of the people who
maintain said code would have a hard time understanding what changed.)

As far as I know, Perl doesn't currently have any binary list
operators, although I see no reason why not.

(For consistency, we'd probably also want to do the same thing to &&
and !, which would be even worse.)

(Actually, even if we're happy with || being inconsistent with ||=,
this would change ||= from providing a scalar context to its rhs to
providing a list context.  This would also break existing code.)

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe