chiark / gitweb /
src/pset-impl.lisp: Introduce a property type for booleans.
[sod] / src / pset-impl.lisp
index 60674ff8b0a712a43e3a0d1bbaa625925643be7a..e6986a5b91bccf384890ac66d61646534b16505e 100644 (file)
@@ -74,6 +74,14 @@ (defun string-to-symbol
                 (error "Symbol `~A' not external in package `~A'"
                        name (package-name package)))))))))
 
+(let ((truish '("true" "t" "yes" "verily"))
+      (falsish '("false" "nil" "no" "nowise")))
+  (defun truishp (string)
+    "Convert STRING to a boolean."
+    (cond ((member string truish :test #'string=) t)
+         ((member string falsish :test #'string=) nil)
+         (t (error "Unrecognized boolean value `~A'" string)))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Property representation.
 
@@ -114,6 +122,20 @@ (defmethod coerce-property-value
     ((value symbol) (type (eql :symbol)) (wanted (eql :id)))
   (frob-identifier (symbol-name value)))
 
+;;; Boolean.
+
+(defmethod coerce-property-value
+    ((value symbol) (type (eql :symbol)) (wanted (eql :boolean)))
+  value)
+
+(defmethod coerce-property-value
+    ((value string) (type (eql :id)) (wanted (eql :boolean)))
+  (truishp value))
+
+(defmethod coerce-property-value
+    ((value integer) (type (eql :int)) (wanted (eql :boolean)))
+  (not (zerop value)))
+
 ;;; Types.
 
 (defmethod coerce-property-value