News for hackers. Stuff that matters.
Re:Learn Lua in 15 Minutes (2013) by corysama on Tuesday June 30, 2020 @07:35PM (#23696074)
Lua was originally created to be used by a group of FORTRAN programmers. Lua starts with 1 because FORTRAN starts with 1. FORTRAN starts with 1 because Math starts with 1 (Sum of f(Xi) for i in 1 to N)
Re:Learn Lua in 15 Minutes (2013) by tzs on Tuesday June 30, 2020 @09:10PM (#23696676)
Sometimes math starts with 1 and sometimes with 0.

I was once implementing some math algorithm whose description had various subscripted variables. Some ran from 0 to whatever, and some ran from 1 to whatever. I was implementing in C++, with each of these variables becoming an array. I didn't want to write var[i-1] all over the place for the ones that ran from 1 in the book--it was a tricky algorithm and for maximum clarity I wanted my code to read as close to the book as possible.

What I did was overload the () operator to make it a 1-based array access operator. I.e., var(i) == var[i-1].

That worked out reasonably, although it probably would have been better just to make the arrays for the 1-based variables one longer and just ignore var[0]. In other words, if var in the text has subscripts that run from 1 through 10, make the var array in C++ 11 long, and just use var[1] through var[10].

Re:Learn Lua in 15 Minutes (2013) by lordgrenville on Wednesday July 01, 2020 @03:08AM (#23698631)
Same story with Julia. Julia is 1-indexed because MATLAB is 1-indexed, and MATLAB is 1-indexed because maths is 1-indexed.