> On Jan 12, 2017, at 6:21 AM, Erich Rast <er...@snafu.de> wrote:
> 
> #lang racket
> (require framework/preferences)
> (provide init-preferences const:app-name const:app-version
>         pref:db-path)
> 
> (define const:app-name "Virtual Assistant")
> (define const:app-version 1.0)
> 
> (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 (definition-key ident)
>  (string->symbol (string-append "pref:" (symbol->string ident))))
> 
> (define-syntax pref
>  (syntax-rules ()
>    [(pref ident) (let ((key (lookup-key ident)))
>                    (unless (preferences:default-set? key)
> (init-preferences)) (preferences:get key))]
>    [(pref ident value) (let ((key (lookup-key ident)))
>                    (unless (preferences:default-set? key)
> (init-preferences)) (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 (definition-key ident)
>                                       (case-lambda
>                                         [() (pref ident)]
>                                         [(value) (pref ident value)]))
>                                     (pref ident default test?))]))



>From what I can tell, you want to turn ‘db-path’ into ‘pref:db-path’ with 
>definition-key. But then your pref macro generates a reference to plain 
>‘db-path’ (you are passing in plain ‘ident’), which is why you get an “unbound 
>identifier” error. 

1. definition-key generates a symbol, not an identifier. 

2. I think you want to attache these prefixes (pref:) in provide (with 
prefix-out) not via macros. 

It should simplify your life a lot. Let me know how this goes. 




> 
> 
> (defpref db-path default-datapath path?)
> 
> (define (init-preferences)
>  (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.

-- 
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