From 33be10b57d00b5fc091e2da23e4c48c02d1e2076 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 8 Dec 2022 16:09:21 +0200 Subject: [collections] Implemented integer-to-list function --- src/collections.lisp | 7 +++++++ src/packages.lisp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/collections.lisp b/src/collections.lisp index b0da74f..84a54a2 100644 --- a/src/collections.lisp +++ b/src/collections.lisp @@ -13,3 +13,10 @@ (defun slice (place &key (begin 0) (end (length place))) "Returns list of elements from begin to end indecies, inclusive" (butlast (nthcdr begin place) (- (length place) end 1))) + +(defun integer-to-list (num &key (min-length 1)) + "Returns a list where each element is a digit" + (loop for i = num then (floor i 10) + for m = (list (mod i 10)) then (push (mod i 10) m) + until (and (= i 0) (> (length m) min-length)) + finally (pop m) (return m))) diff --git a/src/packages.lisp b/src/packages.lisp index 802ec3a..ca6df6b 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -17,7 +17,8 @@ (:use :cl) (:export :push-back :pop-back - :slice) + :slice + :integer-to-list) (:documentation "List functions")) (defpackage senzill.io -- cgit v1.2.3