develooper Front page | perl.perl5.porters | Postings from November 2015

Re: RFC: what to do about bitwise string operators (related to [perl#63574])

Thread Previous | Thread Next
From:
Bo Lindbergh
Date:
November 17, 2015 06:48
Subject:
Re: RFC: what to do about bitwise string operators (related to [perl#63574])
Message ID:
DE07C5C1-E6AB-42D3-A4DD-7600E0D3265B@gmail.com
Quoth Karl Williamson:
> I still don't think that is useful in general.  Code points are not generally assigned where the relationship between them is meaningful in bit operations ways.

There is one use case for bitwise operations on code points:
you can find the length of the common prefix of two strings
by xoring them and counting leading NULs in the result.

    sub common_prefix_length
    {
        ($_[0] ^ $_[1]) =~ /^\A\0*/;
        return $+[0];
    }


Unrelated strong opinion: since docs for the string bitwise ops
and for the vec function reference each other, both should treat
high codepoints in the same way.  Back in the bytes-only days,
it was the case that

    vec(($a & $b), $i, $w) == vec($a, $i, $w) & vec($b, $i, $w)

(and so on for the other binary bitwise ops).  This is no longer true
for strings containing high codepoints.


/Bo Lindbergh


Thread Previous | 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