Re: Possible improvement to slice opperations.



Magnus Lycka wrote:
Ron Adam wrote:
ONES BASED NEGATIVE INDEXING

I think Ron's idea is taking off from my observation that if one's complement, rather than negation, was used to specify measure-from- right, we would have a simple consistent system (although I also observed it is far too late to do that to Python now). Using such a system should not define things as below:

  | a | b | c |
  +---+---+---+
 -4  -3  -2  -1
but rather use a form like:
>>   | a | b | c |
>>   +---+---+---+
>>  ~3  ~2  ~1  ~0

The '~' is the binary not symbol which when used
with integers returns the two's compliment.
Actually, the ~ operator is the one's complement operator.

> For calculated values on the slice borders, you still
> have -1 as end value.
But if you are defining the from-right as ones complement,
you use one's complement on the calculated values and
all proceeds happily.  Since this could happen in Python,
perhaps we should call it Pythoñ.

a[1:~1] -> center, one position from both ends.

This is just a convoluted way of writing a[1:-2], which is exactly the same as you would write today.

Actually, a[1 : -1] is how you get to drop the first and last characters today. I suspect you knew this and were just a bit in a hurry criticizing a lame-brained scheme.

-Scott David Daniels
Scott.Daniels@xxxxxxx
.



Relevant Pages

  • Re: Numerics, NaNs, IEEE 754 and C99
    ... |>> complement - Python does not do that. ... A 'twos complement' class would be ... All it does is to trap the exception ... subclause 7.2 - Division by Zero ...
    (comp.lang.python)
  • Re: Possible improvement to slice opperations.
    ... But if you are defining the from-right as ones complement, you use one's complement on the calculated values and all proceeds happily. ... It does have the merit of allowing someone to write ... to remove n characters from each end of the string. ... Frankly I'd rather deal with the Python that exists now than wrap my head around this particular suggestion. ...
    (comp.lang.python)
  • Re: Possible improvement to slice opperations.
    ... complement, rather than negation, was used to specify measure-from- ... we would have a simple consistent system (although I also ... But if you are defining the from-right as ones complement, ... Since this could happen in Python, ...
    (comp.lang.python)
  • twos complement bytes
    ... I'm dabbling with AVR's for a project I have and that means I have to ... Because my AVR will be tethered to my laptop, ... I am writing most of my logic in python, in the hopes of using at ... what two's complement was, I then thought of how I would handle this ...
    (comp.lang.python)
  • Re: Upcoming tour...
    ... did specify 'realistic' choices!! ... Martin wrote: ... complement the current setlist...? ... Black Diamond Bay ...
    (rec.music.dylan)