4 ms·
In the case of Mathematica, 1-based indexing also makes sense in the context of it being a lisp-like language where everything is an expression that can be repr
by rexpress 7y ago
In the case of Mathematica, 1-based indexing also makes sense in the context of it being a lisp-like language where everything is an expression that can be represented as a tree.
So in the case of
exp = x + y + z
this is syntactic sugar for
exp = Plus[x, y, z]
As expected with 1-based indexing exp[[1]] returns x, but the zero index can also be used to access the head of the expression, so exp[[0]] returns Plus.
Another nice property of 1-based indexing in Mathematica's case is that by using negative indices you can access elements in the reverse direction, so exp[[-1]] would return z, and exp[[-3]] would return x.