From 45126b5bc5ded7dc056717d017b2413921b3e42a Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 22 Oct 2022 08:41:16 -0500 Subject: Modify: insert-nth to support negative indies --- utilities.lisp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'utilities.lisp') 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 -- cgit v1.2.3