aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-06-14 23:51:05 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-06-14 23:51:59 +0200
commit7d06b0424d780639c50169cc17eeab66a7663a3a (patch)
tree54d891a55e32fcbf89e0b88dd2abebe7989add1e
parentMap all fields into types. (diff)
downloadcalp-7d06b0424d780639c50169cc17eeab66a7663a3a.tar.gz
calp-7d06b0424d780639c50169cc17eeab66a7663a3a.tar.xz
Repaired ability to set config value to #f.
-rw-r--r--module/util/config.scm31
1 files changed, 18 insertions, 13 deletions
diff --git a/module/util/config.scm b/module/util/config.scm
index 122fc0d1..0b6677fa 100644
--- a/module/util/config.scm
+++ b/module/util/config.scm
@@ -35,6 +35,9 @@
;; similar to emacs defcustom
+;; NOTE that it's valid to set a value (or default value) to #f
+;; but that any #:pre procedure can only return #f to indicate
+;; failure.
(define-macro (define-config name default-value documentation . rest)
(let ((make-config '(@@ (util config) make-config))
(config-values '(@@ (util config) config-values))
@@ -82,19 +85,21 @@
(define-public (set-config! key value)
(cond [(hashq-ref config-values key)
=> (lambda (conf)
- (aif (or (not value)
- ((config-attribute conf #:pre identity)
- value))
- (begin
- (set-value! conf it)
- ((config-attribute conf #:post identity) it))
-
- (throw 'config-error 'set-config!
- "~a->~a = ~s is invalid,~%Field doc is \"~a\""
- (module-name (get-source-module conf))
- key value
- (get-documentation conf))
- ))]
+ (cond [(not value)
+ (set-value! conf #f)
+ ((config-attribute conf #:post identity) #f)]
+ [((config-attribute conf #:pre identity)
+ value)
+ => (lambda (it)
+ (set-value! conf it)
+ ((config-attribute conf #:post identity) it))]
+ [else
+ (throw 'config-error 'set-config!
+ "~a->~a = ~s is invalid,~%Field doc is \"~a\""
+ (module-name (get-source-module conf))
+ key value
+ (get-documentation conf))])
+ )]
[else (hashq-set! config-values key (make-unconfig value))]))
;; unique symbol here since #f is a valid configuration value.