aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-10-23 10:24:18 -0500
committerColin Okay <colin@cicadas.surf>2022-10-23 10:24:18 -0500
commit15cbf6b594e81fddc5ad4666789855f85faf741b (patch)
treef0b0fb0fde6fcccea0163cd2eaff1d3a159f24eb
parent45126b5bc5ded7dc056717d017b2413921b3e42a (diff)
Add: pop-nth
-rw-r--r--utilities.lisp8
1 files changed, 8 insertions, 0 deletions
diff --git a/utilities.lisp b/utilities.lisp
index 214189f..69ddcfe 100644
--- a/utilities.lisp
+++ b/utilities.lisp
@@ -55,3 +55,11 @@
(setf (nth n list) (nth m list)
(nth m list) tmp)
list))
+
+(defun pop-nth (n list &optional share-tail)
+ (when (minusp n)
+ (setf n (+ n (length list))))
+ (multiple-value-bind (front back) (take n list share-tail)
+ (values
+ (nconc front (cdr back))
+ (car back))))