From cd6ac8930db6ad3b866b4b8398a25b49c3767a5b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 9 Jul 2025 21:31:43 +0100 Subject: Overhaul Loads of changes, some which I wasn't sure what I was on when doing them --- lib/functions.lisp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'lib/functions.lisp') 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)) -- cgit v1.2.3-13-gbd6f