aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Pouar <pouar@pouar.net>2020-07-14 15:04:16 -0500
committerGravatar Pouar <pouar@pouar.net>2020-07-14 17:56:43 -0500
commit42ebec5969174a67166cab4c3bbd1bd6c6951933 (patch)
tree10058bec585a6234e0659c821d487e7099286193
parenttype declarations (diff)
avoid non tail recursive function
-rw-r--r--core/util.lisp7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/util.lisp b/core/util.lisp
index 2814fae..ac4d528 100644
--- a/core/util.lisp
+++ b/core/util.lisp
@@ -20,9 +20,10 @@
(remove-if (constantly t) sequence :start n :count 1))
(declaim (ftype (function (list t unsigned-byte) list)))
(defun insert (list value n)
- (if (<= n 0)
- (cons value list)
- (cons (car list) (insert (cdr list) value (- n 1)))))
+ (if (= n 0)
+ (push value list)
+ (push value (cdr (nthcdr (1- n) list))))
+ list)
(define-modify-macro insertf (value n) insert)
(declaim (inline substitute/swapped-arguments remove-if/swapped-arguments))
(defun substitute/swapped-arguments (sequence new old &rest keyword-arguments)