[DFW.pm] Homework for the list, and for Oct 08 meeting

Patrick R. Michaud pmichaud at pobox.com
Thu Sep 11 14:43:19 PDT 2014


On Thu, Sep 11, 2014 at 03:41:04PM -0500, Robert Flach wrote:
> (on the other hand usurping bitwise & for anything else is a 
> horrible abuse of long-time programmers trust; can't believe 
> perl6 went there)

Oh, changing & (and |) makes perfect sense to me.  Bitwise operations
are no longer as commonly used as they once were, so huffmanization says
we should give them longer forms and save the single-character operators
for something more useful.

Beyond that, there are in fact several meanings of "bitwise and"
depending on how you look at the array of bits, so Perl 6 makes
the different types of bitwise (and|or|xor) explicit:

    +&  +|  +^   numeric bitwise and, or, xor  (e.g., signed)
    ~&  ~|  ~^   string buffer bitwise and, or, xor
    ?&  ?|  ?^   boolean and, or, xor  (treats arguments as Bool)

The above pattern makes even more sense when you consider the bit shifting
operators... Perl 5's  >> bit shift operator becomes

    +>  numeric shift right (extends sign)
    ~>  string buffer shift right  (doesn't extend sign)

This frees up the << and >> symbols for much more useful (and common)
operations as well.  And the consistent use of +/~/? to signify
numeric/string/boolean pervades the entire language, thus reducing
special cases and character sequences that have to be remembered.

As far as changing & being an abuse of "long-time programmers' trust"; 
perhaps so.  In Perl 6 we're focused more on making things better for 
generations of future programmers, even if it somewhat inconveniences 
the existing ones.  Most long-time programmers coming to Perl 6 have 
been able to adapt from Perl 5's "&" bitwise and to Perl 6's "+&" 
without much fuss.  And being able to write code like

    if $value == 2 | 3 | 7 | 11 | 12 { ... }

    if $spot ~~ Dog | Cat { ... }

feels like a far more natural and useful purpose of "|" and "&" as 
operators, especially for newbie programmers.

Pm


More information about the Dfw-pm mailing list