commit 8da2e0f37281873aa2e9c0ad91a76e3eb75cea65
Author: Martin Ashby <martin@ashbysoft.com>
Date: Sun, 7 Dec 2025 06:28:32 +0000
Just following along practical common lisp to start with
Diffstat:
3 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/01.lisp b/01.lisp
@@ -0,0 +1,67 @@
+(defvar *db* nil)
+
+(defun add-record (cd)
+ (push cd *db*))
+
+(defun make-cd (title artist rating ripped)
+ (list :title title :artist artist :rating rating :ripped ripped))
+
+(defun dump-db ()
+ (dolist (cd *db*)
+ (format t "~{~a:~10t~a~%~}~%" cd)))
+
+(defun prompt-read (prompt)
+ (format *query-io* "~a: " prompt)
+ (force-output *query-io*)
+ (read-line *query-io*))
+
+(defun prompt-for-cd ()
+ (make-cd
+ (prompt-read "Title")
+ (prompt-read "Artist")
+ (or (parse-integer (prompt-read "Rating") :junk-allowed t) 0)
+ (y-or-n-p "Ripped [y/n]: ")))
+
+(defun add-cds ()
+ (loop (add-record (prompt-for-cd))
+ (if (not (y-or-n-p "Another? [y/n]: ")) (return))))
+
+(defun save-db (filename)
+ (with-open-file (out filename :direction :output :if-exists :supersede)
+ (with-standard-io-syntax
+ (print *db* out))))
+
+(defun load-db (filename)
+ (with-open-file (in filename)
+ (with-standard-io-syntax
+ (setf *db* (read in)))))
+
+(defun select (selector)
+ (remove-if-not
+ selector
+ *db*))
+
+(defun artist-selector (artist)
+ #'(lambda (cd) (equal (getf cd :artist) artist)))
+
+(defun update (selector-fn &key title artist rating (ripped nil ripped-p))
+ (setf *db*
+ (mapcar
+ #'(lambda (row)
+ (when (funcall selector-fn row)
+ (if title (setf (getf row :title) title))
+ (if artist (setf (getf row :artist) artist))
+ (if rating (setf (getf row :rating) rating))
+ (if ripped-p (setf (getf row :ripped) ripped)))
+ row) *db*)))
+
+
+(defun make-comparison-expr (field value)
+ `(equal (getf cd ,field) ,value))
+
+(defun make-comparisons-list (fields)
+ (loop while fields
+ collecting (make-comparison-expr (pop fields) (pop fields))))
+
+(defmacro where (&rest clauses)
+ `#'(lambda (cd) (and ,@(make-comparisons-list clauses))))
+\ No newline at end of file
diff --git a/README.md b/README.md
@@ -0,0 +1,3 @@
+AoC 2026
+
+Advent of Code 2026 solutions, this year in common-lisp
+\ No newline at end of file
diff --git a/mycds.db b/mycds.db
@@ -0,0 +1,2 @@
+
+((:TITLE "Who Killed the Zutons" :ARTIST "The Zutons" :RATING 10 :RIPPED T) (:TITLE "Cure for the itch" :ARTIST "Linkin Park" :RATING 9 :RIPPED T) (:TITLE "By Myself" :ARTIST "Linkin Park" :RATING 8 :RIPPED T) (:TITLE "Numb" :ARTIST "Linkin Park" :RATING 8 :RIPPED T))
+\ No newline at end of file