diff options
author | Colin Okay <colin@cicadas.surf> | 2022-10-22 08:41:16 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-10-22 08:41:16 -0500 |
commit | 45126b5bc5ded7dc056717d017b2413921b3e42a (patch) | |
tree | 7bb6156124f108f0ae6e4c1237c2a6cd5b2426d1 /utilities.lisp | |
parent | 03029efd07ad5273818e585a9b94472dbfcc06e6 (diff) |
Modify: insert-nth to support negative indies
Diffstat (limited to 'utilities.lisp')
-rw-r--r-- | utilities.lisp | 6 |
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 |