diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-10 06:31:43 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-11 00:40:19 +0000 |
commit | ef572b992b57011efd6dbfe649b0ba68f5f5f320 (patch) | |
tree | 587be7464a63920723a88220bd2b1809a5eb0d3e | |
parent | 5a48b66dd649a4dafce56749487f8060637e452c (diff) | |
download | cantedraw-ef572b992b57011efd6dbfe649b0ba68f5f5f320.tar.gz cantedraw-ef572b992b57011efd6dbfe649b0ba68f5f5f320.tar.bz2 cantedraw-ef572b992b57011efd6dbfe649b0ba68f5f5f320.zip |
Introduce lib.functions which includes helper functions
Splitting macros and functions into different packages and source code
makes it easier to look at. Functions currently implemented:
- range: like Python's range
- parse-integer*: parse-integer but junk-allowed is set to t.
-rw-r--r-- | lib.functions.lisp | 31 | ||||
-rw-r--r-- | main.lisp | 2 | ||||
-rw-r--r-- | odraw.asd | 1 | ||||
-rw-r--r-- | packages.lisp | 6 |
4 files changed, 39 insertions, 1 deletions
diff --git a/lib.functions.lisp b/lib.functions.lisp new file mode 100644 index 0000000..c7b3ed1 --- /dev/null +++ b/lib.functions.lisp @@ -0,0 +1,31 @@ +;;; lib.functions.lisp - 2025-02-09 + +;; Copyright (C) 2025 Aryadev Chavali + +;; This program is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +;; FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for +;; details. + +;; You may distribute and modify this code under the terms of the GNU General +;; Public License Version 2, which you should have received a copy of along with +;; this program. If not, please go to <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Helpful functions for usage throughout the project. + +;;; Code: + +(in-package :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." + (if (<= end start) + (error (format nil "~a < ~a" end start)) + (loop :for i :from start :to (1- end) :by step + :collect i))) + +(fn parse-integer* (inp) (-> (string) (or integer list)) + (parse-integer inp :junk-allowed t)) @@ -28,7 +28,7 @@ (fn parse-integers (input) (-> (string) list) (->> input (uiop:split-string) - (mapcar (lambda (s) (parse-integer s :junk-allowed t))) + (mapcar #'parse-integer*) (remove-if #'null))) (fn read-integers () (-> nil list) @@ -2,6 +2,7 @@ :depends-on (:deploy) :components ((:file "packages") (:file "lib.macros") + (:file "lib.functions") (:file "main")) :build-operation "deploy-op" :build-pathname "odraw" diff --git a/packages.lisp b/packages.lisp index f7e56a6..aff5b68 100644 --- a/packages.lisp +++ b/packages.lisp @@ -24,6 +24,12 @@ :while :-> :fn)) +(defpackage lib.functions + (:use :cl :lib.macros) + (:export + :range + :parse-integer*)) + (defpackage main (:use :cl :lib.macros) (:export :start)) |