diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-07-09 21:31:43 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-07-10 00:08:23 +0100 |
commit | cd6ac8930db6ad3b866b4b8398a25b49c3767a5b (patch) | |
tree | b7d85e0845f1d0aa1b17ee3a0105823190bba4be /lib | |
parent | 062b5f59d74bda9710c3b532648658a4a7910290 (diff) | |
download | cantedraw-master.tar.gz cantedraw-master.tar.bz2 cantedraw-master.zip |
Overhaulmaster
Loads of changes, some which I wasn't sure what I was on when doing
them
Diffstat (limited to 'lib')
-rw-r--r-- | lib/functions.lisp | 19 | ||||
-rw-r--r-- | lib/macros.lisp | 5 |
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))) |