[E-Lang] Operators #7: Bit/Set operators

Mark S. Miller markm@caplet.com
Sat, 07 Apr 2001 12:06:52 -0700


--=====================_167506525==_.ALT
Content-Type: text/plain; charset="us-ascii"

Also on http://www.python.org/doc/current/ref/numeric-types.html are 
Python's operators for treating an integer as a set of bit positions.  As 
discussed, besides applying these to E's integers, these are the ones to 
think about generalizing to collections.

    x << y  ->  x op__lshift(y)
    x >> y  ->  x op__rshift(y)
    x & y   ->  x op__and(y)
    x ^ y   ->  x op__xor(y)
    x | y   ->  x op__or(y)
    ~x      ->  x op__invert(y)
    x & ~y  ->  x op__mask(y)  # suggested by Tyler, not Python

It's clear how op__and, op__or, op__xor, and op__mask generalize to sets and 
regions.  It's also clear how op__invert generalizes to regions.  I think 
everyone's happy with op__or on lists being append, though with lists not 
being unified with multisets this is now harder to justify.

For all other generalization of these operators to collections, I expect 
more controversy.  In particular, Dean's arguments against manipulating maps 
by treating them as sets of keys, with the values along for the ride.


        Cheers,
        --MarkM

--=====================_167506525==_.ALT
Content-Type: text/html; charset="us-ascii"

Also on
http://www.python.org/doc/current/ref/numeric-types.html
are 
Python's operators for treating an integer as a set of bit positions.  As
discussed, besides applying these to E's integers, these are the ones to
think about generalizing to collections.

    x << y  ->  x op__lshift(y)
    x >> y  ->  x op__rshift(y)
    x & y   ->  x op__and(y)
    x ^ y   ->  x op__xor(y)
    x | y   ->  x op__or(y)
    ~x      ->  x op__invert(y)
    x & ~y  ->  x op__mask(y)  # suggested by Tyler, not Python

It's clear how op__and, op__or, op__xor, and op__mask generalize to sets and
regions.  It's also clear how op__invert generalizes to regions.  I think
everyone's happy with op__or on lists being append, though with lists not
being unified with multisets this is now harder to justify.

For all other generalization of these operators to collections, I expect
more controversy.  In particular, Dean's arguments against manipulating maps
by treating them as sets of keys, with the values along for the ride.


        Cheers,
        --MarkM
--=====================_167506525==_.ALT--