;; // https://adventofcode.com/2022/day/21 ;; well, this seems like this could be done with (eval) ;; would it be possible for me to also translate ;; xxx + yyy into (call xxx) + (call yyy) ;; that would be neat (in-package :day-21) ;; so. have mashmap from symbol name into operation ;; and have (my-eval)? ;; it will take symbol name, and either return number directly from the map ;; or will wrap the names into my-eval and run operation on them? ;; is there a way to have less code and reuse existing lisp things? ;; if there's direct number, i could just run (defparameter lfqf 4) ;; and then execute root directly, i think ;; or what, i'd need to also define all the intermediate symbols, ;; (setq a (+ c d)) ; complains that C is unbound ;; how could this be a lazy eval? ;; well. hm ;; i could define all of these as macroses? (defmacro *test-monkey-hmdt* () 32) (+ 3 (*test-monkey-hmdt*)) ;; yup, i guess (defparameter *test-monkey-sllz* 4) (eval *test-monkey-sllz*) (defparameter *test-monkey-ljgn* 2) (defparameter *my-operation* '(+ *test-monkey-sllz* *test-monkey-ljgn*)) *my-operation* (eval *my-operation*) ; well, that works ok ;; so, read all of these things as parameters. ;; "root: pppw + sjmn " (mapcar #'intern (ppcre:split " " "root: pppw + sjmn ")) (mapcar #'parse-integer-or-symbol (ppcre:split " " "root: 44")) (ppcre:regex-replace ":" "root: pppw + sjmn " "") (line-to-quoted-operation "root: pppw + sjmn") (eval (line-to-quoted-operation "dbpl: 5")) ;; well, i'd want to put quoted expression into parameter? ;; and now i can remove quoting of the defparameter? ;; and actually define all of the parameters? (loop for line in (uiop:read-file-lines "day21-test.txt") for definition = (line-to-quoted-operation line) do (eval definition)) (eval root) (load-file-defs "day21-test.txt") (eval root)