develooper Front page | perl.perl5.porters | Postings from September 2005

Re: [perl #969] shifting of bitvecs considered broken

Thread Previous
From:
Yitzchak Scott-Thoennes
Date:
September 28, 2005 13:10
Subject:
Re: [perl #969] shifting of bitvecs considered broken
Message ID:
20050928200951.GA5652@efn.org
On Wed, Sep 28, 2005 at 09:01:12AM +0300, Jarkko Hietaniemi wrote:
> Steve Peters via RT wrote:
> > This thread sort of went off on a tangent.  What should the expected
> > results be?
> 
> Well, ASSUMING that there will be in future a way to make shifting of
> bitvecs to work as, well, shifting of bitvecs, instead of the shift ops
> assuming their arguments are numbers (which must be kept as the default
> way of doing things because of hysterical raisins)... assuming this new
> pragma is called "bitvec":
> 
> perl -Mbitvec -wle '$b = "";
> vec($b, 0, 1) = 1;
> print unpack("b*",$b);
> $b<<=1;
> print unpack("b*", $b)'
> 10000000
> 01000000

I'd rather see a pragma that allowed changing how &,|, etc. work also.
Maybe:
   use bitvec auto => -shiftops;

to allow shifting as bitvecs if they've never been used in numeric context

   use bitvec string => -shiftops;

to have the shift ops always shift as bitvecs, and

   use bitvec numeric => -shiftops;

being the default, making the ops always assume numbers.

It would also allow affecting the bitwise ops (~, &, |, ^) which
would default to:

   use bitvec auto => -bitwise;

And
   use bitvec default => -all;

would restore the defaults.

I know I'd use

   use bitvec string => -all;

often in limited lexical scopes.

Thread Previous


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