aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/functions.lisp19
-rw-r--r--lib/macros.lisp5
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/functions.lisp b/lib/functions.lisp
index daeac0a..12b1df5 100644
--- a/lib/functions.lisp
+++ b/lib/functions.lisp
@@ -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))
diff --git a/lib/macros.lisp b/lib/macros.lisp
index c60b867..2c4bdd8 100644
--- a/lib/macros.lisp
+++ b/lib/macros.lisp
@@ -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)))