[plt-scheme] Linking Scheme- and C-variables
[snip]
> (module hooked-vars mzscheme
> (provide def-hooked-var)
> (define-syntax (def-hooked-var stx)
> (syntax-case stx ()
> ((_ var val hook) (identifier? #'var)
> (with-syntax ((hidden-var
> (datum->syntax-object
> #'var
> (string->symbol
> (string-append
> (symbol->string (syntax-e #'var))
>
> "-hidden-value"))
> #'var)))
> #'(begin (define hidden-var val)
> (define-syntax var
> (make-set!-transformer
> (lambda (stx)
> (syntax-case stx (set!)
> ((set! var new-val)
> #'(set! hidden-var (hook
> new-val)))
> ((var . xs) #'(hidden-var
> . xs))
> (var
> #'hidden-var)))))))))))
>
> For example:
>
> > (require hooked-vars)
> > (define a 1)
> > (def-hooked-var b 1 (lambda (new) (set! a new)
> new))
> > (set! b 3)
> > b
> 3
> > a
> 3
That will link them in MzScheme, but from C's point of
view, b would still only be accessable as a
Scheme_Object*, right?
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/