Paul Rubin wrote:
"Dan Bishop" <[EMAIL PROTECTED]> 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.

I write Python code that interoperates with Fortran code all the time (and write Fortran code that interoperates with Python code, too). Very, very rarely do I have to explicitly do any conversions. They only show up when a Fortran subroutine requires an index in its argument list.


In Fortran, I do Fortran. In Python, I do Python.

Yes, there is some effort required when translating some code or pseudo-code that uses 1-based indexing. Having done this a number of times, I haven't found it to be much of a burden.

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.

I contend that if they had decided to just write the C versions as C instead of C-wishing-it-were-Fortran, they would have made a much better library. Still sucky, but that's another story.


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.

There's nothing that stops you from writing a class that does this. I believe someone posted such a one to this thread.


I have yet to see a concrete proposal on how to make lists operate like this.

--
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to