chiark
/
gitweb
/
~mdw
/
sod
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ffaadb2
)
src/pset-impl.lisp: Convert strings to booleans using a hash-table.
author
Mark Wooding
<mdw@distorted.org.uk>
Mon, 12 Aug 2019 10:12:55 +0000
(11:12 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Mon, 12 Aug 2019 11:40:24 +0000
(12:40 +0100)
src/pset-impl.lisp
patch
|
blob
|
blame
|
history
diff --git
a/src/pset-impl.lisp
b/src/pset-impl.lisp
index 338306aca5943c907382a08b4731c0e9699d3040..f5650cf90c558c1c962aae04f40cf75e34c2ff4e 100644
(file)
--- 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)))))))))
(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."
(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.
;;;--------------------------------------------------------------------------
;;; Property representation.