[erlang-questions] Improve $handle_undefined_function

Richard O'Keefe ok@REDACTED
Fri Jan 25 02:59:20 CET 2013


> On 01/24/2013 06:12 PM, Robert Virding wrote:
>> 
>> What is it with zero-based indexes that make people so morbidly
>> fascinated by them.

Dijkstra has explained this at some length in one of his papers.

As for me, I find that working with half-open [Start,End) intervals
in arrays substantially reduces the rate at which I make off-by-one
errors.

I've built a Smalltalk system, complete with 1-origin indexing
everywhere.  The one thing that saves me from errors is the Smalltalk
practice of using higher-order whole-collection operations that don't
mention indices at all.

When I designed the string processing library in Quintus Prolog,
I chose to avoid indices everywhere that I possibly could and to
specify the substring B in ABC as

    substring(Whole, Part, LenA, LenB, LenC)

where Prolog could of course solve for any of LenA, LenB, LenC.
So I could say "4 characters 3 before the end" _,4,3 or
"everything but the first 2 and last 5" 2,_,5 or "skip 7 and
take 9" 7,9,_ or even let the predicate find things by
searching.

It was clearly documented that all these and similar arguments
were *lengths* of substrings.

And I got complaints about using 0-origin indexing, when none
of these arguments was an index!





More information about the erlang-questions mailing list