You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
986 B

#lang racket
(require racket/exn)
(define-syntax-rule (reprovide e0 e ...)
(require e0 e ...)
(provide (all-from-out e0 e ...))))
(provide load-config
(define (assoc-val key assoc-list)
(cdr (assoc key assoc-list)))
;; Example (load-config "/tmp/conf.rkt")
(define (load-config config-path)
(with-handlers ([exn:fail:filesystem:errno?
(lambda (exn)
(error (exn->string exn)))])
(let [(eval-ns (make-base-namespace))
(params (make-hash))]
(let [(settings (file->list config-path))]
(for [(name:value settings)]
(let* [(n (car name:value)); evaluate the 'value' expression
(v (cdr name:value))
(v (eval (quasiquote (,@v)) eval-ns))]
(hash-set! params n v)