From: Mark Wooding Date: Mon, 12 Aug 2019 10:12:55 +0000 (+0100) Subject: src/pset-impl.lisp: Convert strings to booleans using a hash-table. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/7ae23d74a4a7ec3b778f48e26d7a81a338a56111 src/pset-impl.lisp: Convert strings to booleans using a hash-table. --- diff --git a/src/pset-impl.lisp b/src/pset-impl.lisp index 338306a..f5650cf 100644 --- a/src/pset-impl.lisp +++ b/src/pset-impl.lisp @@ -74,13 +74,16 @@ (defun string-to-symbol (error "Symbol `~A' not external in package `~A'" name (package-name package))))))))) -(let ((truish '("true" "t" "yes" "on" "verily")) - (falsish '("false" "nil" "no" "off" "nowise"))) +(let ((truth-map (make-hash-table :test #'equalp))) + (dolist (string '("true" "t" "yes" "on" "verily")) + (setf (gethash string truth-map) t)) + (dolist (string '("false" "nil" "no" "off" "nowise")) + (setf (gethash string truth-map) nil)) (defun truishp (string) "Convert STRING to a boolean." - (cond ((member string truish :test #'string-equal) t) - ((member string falsish :test #'string-equal) nil) - (t (error "Unrecognized boolean value `~A'" string))))) + (multiple-value-bind (val foundp) (gethash string truth-map) + (if foundp val + (error "Unrecognized boolean value `~A'" string))))) ;;;-------------------------------------------------------------------------- ;;; Property representation.