[Edu-sig] Re: Confusion with slice notation

Christopher A. Craig com-nospam at ccraig.org
Mon Jan 5 14:23:40 EST 2004


com-nospam at ccraig.org (Christopher A. Craig) writes:

> Or they are both the position of the start of the element from the
> start or end of the list.  Which is why I like my way of doing
> things.  

Sorry to reply to myself, but I thought it important to note that this
(not coincidentally) is very similar to how indexing actually works.
A list is a list of pointers (lets say 32 bits (4 bytes) for the sake
of argument) and a[0:3] returns a list containing the contents of the
pointers between the start of the list and 3*4-bytes after the start.
Similarly a[-3:-1] returns a list containing the contents of the
pointers between 3*4-bytes before the end and 1*4-bytes before the end
and a[2] returns the contents of the pointer which begins 2*4bytes
after the start of the list.  (Which, also not coincidentally, is why
C did it that way, a[3] is changed by the compiler to 
<location of a>+(3*<size of an element of a>).)

-- 
Christopher A. Craig <com-nospam at ccraig.org>
ed is the standard text editor




More information about the Edu-sig mailing list