Why Python does *SLICING* the way it does??

Paul Rubin http
Thu Apr 21 16:29:10 EDT 2005


"Dan Bishop" <danb_83 at yahoo.com> writes:
> Name a problem space that inherently requires arrays to be 1-based
> rather than 0-based.

"inherently" is too strong a word, since after all, we could do all
our computing with Turing machines.

Some algorithms are specified in terms of 1-based arrays.  And most
Fortran programs are written in terms of 1-based arrays.  So if you
want to implement a 1-based specification in Python, or write Python
code that interoperates with Fortran code, you either need 1-based
arrays in Python or else you need messy conversions all over your
Python code.

The book "Numerical Recipes in C" contains a lot of numerical
subroutines written in C, loosely based on Fortran counterparts from
the original Numerical Recipes book.  The C routines are full of messy
conversions from 0-based to 1-based.  Ugh.

Again, this (along with nested scopes and various other things) was
all figured out by the Algol-60 designers almost 50 years ago.  In
Algol-60 you could just say "integer x(3..20)" and get a 3-based array
(I may have the syntax slightly wrong by now).  It was useful and took
care of this problem.



More information about the Python-list mailing list