develooper Front page | perl.perl5.porters | Postings from April 2013

remove ambiguity from operators

Thread Next
From:
Dr.Ruud
Date:
April 20, 2013 07:15
Subject:
remove ambiguity from operators
Message ID:
20130420071508.15928.qmail@lists-nntp.develooper.com

On 2013-04-20 02:27, Ben Morrow wrote on c.l.p.misc:

 > the bitops' behaviour is *not* consistent with the rest of Perl.
 > Unlike some languages, the + operator (for instance) does not choose
 > to be 'addition' or 'concatenation' based on the dynamic types of its
 > arguments; instead, it always coerces its arguments to numbers and
 > performs addition. Similarly, Perl has separate == and eq equality
 > operators which coerce their arguments to number or string. The
 > bitwise ops should have been implemented the same way,
 > with &, |, ^ and ~ always coercing their arguments to numbers
 > and (say) ba, bo, bx and bn always coercing them to strings.

What is needed to get rid of this anomaly? Is it worth it?

It should of course be optional, for example via "use strict 'bitops';".

   my $char = "X";

   my $flip = "A" ^ "a";
   $char ^= $flip;

   my $flip = "A" bx "a";
   $char bx= $flip;

   my $flip = "A" bit_xor "a";
   $char bit_xor= $flip;

-- 
Ruud

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About