From 279437cb81478bc5807674d15120fb38f7ebc3c3 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 10 Feb 2025 07:25:43 +0000 Subject: Implement `split` function. Given a list and index into that list, return a cons where the car is all elements up to that index (exclusive) and the cdr is the rest of the list. --- lib.functions.lisp | 4 ++++ packages.lisp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib.functions.lisp b/lib.functions.lisp index 30c1e64..8eb2304 100644 --- a/lib.functions.lisp +++ b/lib.functions.lisp @@ -32,3 +32,7 @@ each member is STEP distance apart." (fn take (n lst) (-> (fixnum list) list) (subseq lst 0 n)) + +(fn split (n lst) (-> (fixnum list) list) + (cons (take n lst) + (subseq lst n))) diff --git a/packages.lisp b/packages.lisp index 58c848e..72d4dc5 100644 --- a/packages.lisp +++ b/packages.lisp @@ -29,7 +29,7 @@ (:use :cl :lib.macros) (:export :parse-integer* - :range :take)) + :range :take :split)) (defpackage main (:use :cl :lib.macros) -- cgit v1.2.3-13-gbd6f