From 35a413167e323f8b0c9ea40fe7599ffb50e9e321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 31 Mar 2020 16:46:02 +0200 Subject: Attempt at decentralized configuration system. Placing all possible configuration items in a central (parameters) module scales really badly. This idea that any module can register configuration parameters is better. The current implementation however has the drawback that it requires that the module exposing the parameter is loaded before the value can be sat, but that scales even worse. A probable solution would be to abandon binding everything to guile's module system, and instead let (util config) provide a `conf-ref' and a `conf-set!' procedures. A `define-configuration' similar to emacs `defcustom' could be of use, mainly for retroactively type checking parameters. --- module/util/config.scm | 30 ++++++++++++++++++++++++++++++ module/util/config/all.scm | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 module/util/config.scm create mode 100644 module/util/config/all.scm (limited to 'module/util') diff --git a/module/util/config.scm b/module/util/config.scm new file mode 100644 index 00000000..46c0bf99 --- /dev/null +++ b/module/util/config.scm @@ -0,0 +1,30 @@ +;;; Commentary: + +;; This file should define all global configurable variables which +;; doesn't belong anywhere else. The config module should then import +;; this module, and set all configs as needed. The config module +;; should also be able to set configs gotten from other parts. + +;;; Code: + +(define-module (util config) + :export (register-config!) + ) + +(define-public (ensure pred?) + (lambda (v) + (unless (pred? v) + (error (format #f "Value [~s] doesn't satisfy condition ~a" + v (or (procedure-name pred?) "")))) + v)) + +(define-macro (register-config! name default-value valid-value?) + `(save-module-excursion + (lambda () + (define mod (resolve-module '(util config all))) + (set-current-module mod) + (module-define! mod (quote ,name) + (make-parameter ,default-value + ,valid-value?)) + (export ,name)) + )) diff --git a/module/util/config/all.scm b/module/util/config/all.scm new file mode 100644 index 00000000..984b1d68 --- /dev/null +++ b/module/util/config/all.scm @@ -0,0 +1,3 @@ +(define-module (util config all) + :use-module (util config)) + -- cgit v1.2.3