Re: Possible improvement to slice opperations.



Scott David Daniels wrote:

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:

I didn't start with your observation in mind, but it ended up there because the only way to extend the indexes past the last item is to not use 0 along with negative index's. And once that's done the '~' forms "just work" without any additional changes. ;-)


Yes, it may be too late for changing Python's built in indexing. And it may also be that the majority may rather use it as is, rather than change it to fix this edge case.


  | 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.

Yes, thanks, my mistake.


 > 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: Twos Complement, Serialization, etc.
    ... I believe the direct assignment to the unsigned variable in pack16() ... line 3 should give us the two's complement negative by C99-6.3.1.3p2. ... `int' that's in range for an `int16_t'. ... 0x8000u, this is unchanged by negation, and now you try to convert ...
    (comp.lang.c)
  • Re: negative hex
    ... On Jun 29, 11:38 am, John Larkin ... the negation of an integer which is itself expressed in hex. ... In 2's complement, if the most significant ... there is nothing that would have prevented the language ...
    (sci.electronics.design)
  • Re: negative hex
    ... John, I've been sitting on the side wondering whether to put in 2c worth, and ... Surely it can't be "negative" if it is a pattern of bits. ... the negation of an integer which is itself expressed in hex. ... In 2's complement, if the most significant ...
    (sci.electronics.design)
  • Re: negative hex
    ... John, I've been sitting on the side wondering whether to put in 2c worth, and ... Surely it can't be "negative" if it is a pattern of bits. ... the negation of an integer which is itself expressed in hex. ... In 2's complement, if the most significant ...
    (sci.electronics.design)
  • Re: Possible improvement to slice opperations.
    ... complement, rather than negation, was used to specify measure-from- right, we would have a simple consistent system. ... 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, ...
    (comp.lang.python)