Discussion: new operators for numerical computation

Alex Martelli alex at magenta.com
Sat Jul 29 08:07:17 EDT 2000


"Huaiyu Zhu" <hzhu at users.sourceforge.net> wrote in message
news:slrn8o42dq.1cq.hzhu at rocket.knowledgetrack.com...
    [snip]
> >| becomes ~or,
> >^ becomes ~xor,
> >& becomes ~and, and
> >~ becomes ~not, reading like bitwise or, bitwise xor etc.
>
> This would indeed be an excellent option if not for backward
compatibility.
    [snip]
> FLAG = bitwise.or(FLAG1, FLAG2, FLAG3, FLAG4, FLAG5, FLAG6, FLAG7, FLAG8)

What an EXCELLENT idea.  shift left/right could also be packaged that
way (or, almost so; 'or' is a reserved words in Python...).

> quite "unpythonic" to let them occupy four unique ascii characters as

Agreed, and worse if you consider << and >>.

> Furthermore, unlike math operators, unless you are designing a logical
> circuit, it is rare to construct complicated formulas with these
operators.
> So brevity is really not important for them.

The 'bitwise' module could supply easily explicit bitfield-extraction
in place of the mask-and-shift idioms, too.

Oh well -- maybe a hint for Python 3000, when backwards compatibility
can be broken...!


Alex






More information about the Python-list mailing list