Loads of changes, some which I wasn't sure what I was on when doing
them
This commit is contained in:
2025-07-09 21:31:43 +01:00
parent 062b5f59d7
commit cd6ac8930d
11 changed files with 76 additions and 69 deletions

View File

@@ -19,21 +19,21 @@
(in-package :cantedraw.lib.functions)
(fn range (start end &optional (step 1)) (-> (fixnum fixnum &optional fixnum) list)
"Make a list of numbers from START to END (exclusive). If STEP is given, then
each member is STEP distance apart."
(fn range (&key (start 0) (end 0) (step 1))
(-> (&key (:start fixnum) (:end fixnum) (:step fixnum))
list)
"Return list of integers in interval [START, END). If STEP is given, then
each member is STEP distance apart i.e. {START + n * STEP | n from 0}.
If END is not given, return interval [0, START)."
(if (< end start)
(error (format nil "~a < ~a" end start))
(loop :for i :from start :to (1- end) :by step
:collect i)))
(fn take (n lst) (-> (fixnum sequence) sequence)
"Return the first N elements of LST."
(subseq lst 0 n))
(fn split (n lst) (-> (fixnum sequence) (values sequence sequence))
"Return CONS where CAR is the first N elements of LST and CDR is the rest."
(values (take n lst)
(values (subseq lst 0 n)
(subseq lst n)))
(fn rev-map (indicator lst &key (key-eq #'eq))
@@ -60,6 +60,3 @@ where key x in A has associations {y in LST : INDICATOR(y) = x}."
:for item :in (coerce lst 'list)
:if (not (member i indices))
:collect item))
(fn sort* (func lst) (-> (function sequence) sequence)
(sort lst func))

View File

@@ -124,3 +124,8 @@ sequentially via ->>"
(defmacro alist-val (key alist)
"Helper macro for getting the value of KEY in ALIST."
`(cdr (assoc ,key ,alist)))
(defmacro call-rev (func-name &rest arguments)
"Call a function with arguments but in reverse
i.e. (call-rev f x1 x2 ... xn) => (f xn ... x2 x1)."
`(,func-name ,@(reverse arguments)))