summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-10-22 08:41:16 -0500
committerColin Okay <colin@cicadas.surf>2022-10-22 08:41:16 -0500
commit45126b5bc5ded7dc056717d017b2413921b3e42a (patch)
tree7bb6156124f108f0ae6e4c1237c2a6cd5b2426d1
parent03029efd07ad5273818e585a9b94472dbfcc06e6 (diff)
Modify: insert-nth to support negative indies
-rw-r--r--utilities.lisp6
1 files changed, 5 insertions, 1 deletions
diff --git a/utilities.lisp b/utilities.lisp
index 972df8a..214189f 100644
--- a/utilities.lisp
+++ b/utilities.lisp
@@ -38,7 +38,11 @@
"Creates a new list, the result of inserting X into the Nth position
of LIST, displacing the rest of the elements by one position. If N
is greater than the length of LIST, X becomes the last element of
- LIST. If N is negative, a list containing just X is returned."
+ LIST. If N is negative, the element is inserted from the back of
+ the list. If the abslute value of -N is greater than the lenght of
+ the list, a list just containing X is returned."
+ (when (minusp n)
+ (setf n (+ 1 n (length list))))
(multiple-value-bind (front back) (take n list)
;; NCONC ok b/c this call to TAKE returns values that do not shre
;; memory with LIST