# HG changeset patch # User Steve Losh # Date 1471898360 0 # Node ID 1d59a2656cfc0ad01d7f62cf835c3ce7f41c14a5 # Parent 7eb23163afcfa2d5fa7d4e474ea325330a11bbbb Use `ensure-gethash` diff -r 7eb23163afcf -r 1d59a2656cfc src/binary-decision-diagrams.lisp --- a/src/binary-decision-diagrams.lisp Sun Aug 21 18:14:23 2016 +0000 +++ b/src/binary-decision-diagrams.lisp Mon Aug 22 20:39:20 2016 +0000 @@ -72,7 +72,7 @@ (let ((nodes (make-hash-table))) (graphviz-digraph (bdd-map-nodes (lambda (node) - (list (gethash-or-init node nodes (gensym)) + (list (ensure-gethash node nodes (gensym)) :label (node-label node) :shape (node-shape node))) bdd) diff -r 7eb23163afcf -r 1d59a2656cfc vendor/make-quickutils.lisp --- a/vendor/make-quickutils.lisp Sun Aug 21 18:14:23 2016 +0000 +++ b/vendor/make-quickutils.lisp Mon Aug 22 20:39:20 2016 +0000 @@ -12,6 +12,7 @@ :define-constant :riffle :tree-collect + :ensure-gethash ; :switch ; :while ; :ensure-boolean diff -r 7eb23163afcf -r 1d59a2656cfc vendor/quickutils.lisp --- a/vendor/quickutils.lisp Sun Aug 21 18:14:23 2016 +0000 +++ b/vendor/quickutils.lisp Mon Aug 22 20:39:20 2016 +0000 @@ -2,7 +2,7 @@ ;;;; See http://quickutil.org for details. ;;;; To regenerate: -;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:WITH-GENSYMS :ONCE-ONLY :COMPOSE :CURRY :RCURRY :N-GRAMS :DEFINE-CONSTANT :RIFFLE :TREE-COLLECT) :ensure-package T :package "SAND.QUICKUTILS") +;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:WITH-GENSYMS :ONCE-ONLY :COMPOSE :CURRY :RCURRY :N-GRAMS :DEFINE-CONSTANT :RIFFLE :TREE-COLLECT :ENSURE-GETHASH) :ensure-package T :package "SAND.QUICKUTILS") (eval-when (:compile-toplevel :load-toplevel :execute) (unless (find-package "SAND.QUICKUTILS") @@ -17,7 +17,8 @@ :MAKE-GENSYM-LIST :ONCE-ONLY :ENSURE-FUNCTION :COMPOSE :CURRY :RCURRY :TAKE :N-GRAMS - :DEFINE-CONSTANT :RIFFLE :TREE-COLLECT)))) + :DEFINE-CONSTANT :RIFFLE :TREE-COLLECT + :ENSURE-GETHASH)))) (deftype string-designator () "A string designator type. A string designator is either a string, a symbol, @@ -268,8 +269,18 @@ :if (listp item) :append (tree-collect predicate item))))) + + (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) (export '(with-gensyms with-unique-names once-only compose curry rcurry - n-grams define-constant riffle tree-collect))) + n-grams define-constant riffle tree-collect ensure-gethash))) ;;;; END OF quickutils.lisp ;;;;