66e86b59fc60

Minor cleanup
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 01 Dec 2018 19:30:27 -0500
parents 0a6b6dba8b90
children e22f6a54b6d5
branches/tags (none)
files advent.asd src/2017/main.lisp vendor/make-quickutils.lisp vendor/quickutils.lisp

Changes

--- a/advent.asd	Sat Dec 01 17:00:00 2018 -0500
+++ b/advent.asd	Sat Dec 01 19:30:27 2018 -0500
@@ -9,9 +9,11 @@
 
                :cl-digraph
                :cl-digraph.dot
+               :cl-interpol
                :cl-ppcre
                :iterate
                :losh
+               :named-readtables
                :split-sequence
                :str
 
--- a/src/2017/main.lisp	Sat Dec 01 17:00:00 2018 -0500
+++ b/src/2017/main.lisp	Sat Dec 01 19:30:27 2018 -0500
@@ -134,8 +134,7 @@
       ((parse-line (line)
          (ppcre:register-groups-bind
              (name (#'parse-integer weight) ((curry #'str:split ", ") holding))
-             (#?/(\w+) \((\d+)\)(?: -> (.+))?/
-              line)
+             (#?/(\w+) \((\d+)\)(?: -> (.+))?/ line)
            (values name weight holding)))
        (insert-edge (digraph pred succ)
          (digraph:insert-vertex digraph pred)
@@ -149,7 +148,8 @@
            (collect-hash (name weight) :into weights :test #'equal)
            (digraph:insert-vertex tower name)
            (map nil (curry #'insert-edge tower name) holding)
-           (finally (return tower)))))
-    (let ((tower (build-tower data)))
+           (finally (return (values tower weights))))))
+    (multiple-value-bind (tower individual-weights) (build-tower data)
+      (declare (ignore individual-weights))
       ;; (digraph.dot:draw tower)
       (first (digraph:roots tower)))))
--- a/vendor/make-quickutils.lisp	Sat Dec 01 17:00:00 2018 -0500
+++ b/vendor/make-quickutils.lisp	Sat Dec 01 19:30:27 2018 -0500
@@ -5,6 +5,7 @@
   :utilities '(
 
                :extremum
+               :ensure-gethash
                :compose
                :curry
                :ensure-keyword
--- a/vendor/quickutils.lisp	Sat Dec 01 17:00:00 2018 -0500
+++ b/vendor/quickutils.lisp	Sat Dec 01 19:30:27 2018 -0500
@@ -2,7 +2,7 @@
 ;;;; See http://quickutil.org for details.
 
 ;;;; To regenerate:
-;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:EXTREMUM :COMPOSE :CURRY :ENSURE-KEYWORD :RANGE :RCURRY :READ-FILE-INTO-STRING :SYMB) :ensure-package T :package "ADVENT.QUICKUTILS")
+;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:EXTREMUM :ENSURE-GETHASH :COMPOSE :CURRY :ENSURE-KEYWORD :RANGE :RCURRY :READ-FILE-INTO-STRING :SYMB) :ensure-package T :package "ADVENT.QUICKUTILS")
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (unless (find-package "ADVENT.QUICKUTILS")
@@ -13,7 +13,7 @@
 (in-package "ADVENT.QUICKUTILS")
 
 (when (boundp '*utilities*)
-  (setf *utilities* (union *utilities* '(:ENSURE-FUNCTION :EXTREMUM :MAKE-GENSYM-LIST :COMPOSE :CURRY :ENSURE-KEYWORD :RANGE :RCURRY :ONCE-ONLY :WITH-OPEN-FILE* :WITH-INPUT-FROM-FILE :READ-FILE-INTO-STRING :MKSTR :SYMB))))
+  (setf *utilities* (union *utilities* '(:ENSURE-FUNCTION :EXTREMUM :ENSURE-GETHASH :MAKE-GENSYM-LIST :COMPOSE :CURRY :ENSURE-KEYWORD :RANGE :RCURRY :ONCE-ONLY :WITH-OPEN-FILE* :WITH-INPUT-FROM-FILE :READ-FILE-INTO-STRING :MKSTR :SYMB))))
 (eval-when (:compile-toplevel :load-toplevel :execute)
   ;;; To propagate return type and allow the compiler to eliminate the IF when
   ;;; it is known if the argument is function or not.
@@ -73,6 +73,16 @@
                     :start start
                     :end end)))))
   
+
+  (defmacro ensure-gethash (key hash-table &optional default)
+    "Like `gethash`, but if `key` is not found in the `hash-table` saves the `default`
+under key before returning it. Secondary return value is true if key was
+already in the table."
+    `(multiple-value-bind (value ok) (gethash ,key ,hash-table)
+       (if ok
+           (values value ok)
+           (values (setf (gethash ,key ,hash-table) ,default) nil))))
+  
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (defun make-gensym-list (length &optional (x "G"))
     "Returns a list of `length` gensyms, each generated as if with a call to `make-gensym`,
@@ -262,6 +272,6 @@
     (values (intern (apply #'mkstr args))))
   
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (export '(extremum compose curry ensure-keyword range rcurry read-file-into-string symb)))
+  (export '(extremum ensure-gethash compose curry ensure-keyword range rcurry read-file-into-string symb)))
 
 ;;;; END OF quickutils.lisp ;;;;