Hacker News new | past | comments | ask | show | jobs | submit login

> Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.

— Stan Kelly-Bootle

(from http://en.wikipedia.org/wiki/Argument_to_moderation )




There are two types of people:

1. People who index from 1.

1. People who index from 0.


Why index from 1 or 0 when you can overwrite $[ in perl and index from ANYWHERE?

(Dammit, as of Perl 5.16 this is not merely deprecated but outsourced to a module ... mutter, grumble)


IIRC Fortran also allows you do to do this.

Another would be Rebol:

  >> a: [0 1 2 3 4 5]
  == [0 1 2 3 4 5]
  
  >> a/1
  == 0
  
  >> a/2
  == 1
  
  >> a: next a
  == [1 2 3 4 5]
  
  >> a/1
  == 1
  
  >> a/2
  == 2
  
  >> a/0
  == 0


Indexing with floats means you need to do rounding. May I suggest a modified version of Banker's Rounding?

http://en.wikipedia.org/wiki/Rounding#Round_half_to_even




Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: