Closed Kyo91 closed 4 years ago
generic-elt on lists & vectors has special logic for handling negative keys:
generic-elt
(when (minusp key) (setf key (- (length obj) key)))
My understanding is that this is for "Python-style" access where we can access the last element of a list with:
my_list[-1]
However the above doesn't seem to work in practice:
RTL-USER> (? '(foo bar) -1) NIL RTL-USER> (? (make-array 10) -1) ;; Debugger: Invalid index 11 for (SIMPLE-VECTOR 10), should be a non-negative integer below 10.
Because the key is negative, generic-elt should be adding the key to the length rather than subtracting it (equivalent to adding the abs val of key).
key
generic-elt
on lists & vectors has special logic for handling negative keys:My understanding is that this is for "Python-style" access where we can access the last element of a list with:
However the above doesn't seem to work in practice:
Because the
key
is negative,generic-elt
should be adding the key to the length rather than subtracting it (equivalent to adding the abs val ofkey
).