Thanks for your your help. Unfortunately, I haven't managed to get my
head around the phases and the question of when symbols are quoted or
evaluated. I tried Matthew Buttericks change but it yields an error:

"format-id: undefined;
 cannot reference an identifier before its definition
  phase: 1"

So I tried to implement Matthias Felleisen's suggestion (see below), but
now I get "home-dir: unbound identifier in module in: home-dir". Why
does this occur and how can I fix this? And is there a way to avoid
quoting db-path when using defpref?

Best,

Erich

--------
#lang racket
(require framework/preferences)
         ;"constants.rkt")
(provide (prefix-out pref: init) (prefix-out pref: db-path))

(define default-datapath (build-path (find-system-path 'home-dir)
"Documents" "va"))

(define *defaults* '())

(define (lookup-key ident)
  (string->symbol (string-append "va:" (symbol->string ident))))

(define-syntax pref
  (syntax-rules ()
    [(pref ident) (let ((key (lookup-key ident)))
                    (unless (preferences:default-set? key) (init))
                    (preferences:get key))]
    [(pref ident value) (let ((key (lookup-key ident)))
                    (unless (preferences:default-set? key) (init))
                    (preferences:set key value))]
    [(pref ident expr test?)
     (set! *defaults* (cons (list (lookup-key ident) expr test?)
*defaults*))]))

(define-syntax defpref
  (syntax-rules ()
    [(defpref ident default test?) (begin
                                     (define ident
                                       (case-lambda
                                         [() (pref ident)]
                                         [(value) (pref ident value)]))
                                     (pref ident default test?))]))
                                    
(defpref 'db-path default-datapath path?)

(define (init)
  (make-directory* default-datapath)
  (for-each
   (lambda (triple)
     (preferences:set-default (first triple) (second triple) (third
triple))) *defaults*))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to