[plt-scheme] Defining global functions with shared state?
I'm trying to create a macro that creates a set of global function
definitions where those functions share some common state. Basically,
the intent is something like the following:
;;; doesn't work, creates local definitions instead of global ones
(let ((state (create-common-state)))
(define (foo x) (use-common-state-one-way x state))
(define (bar x) (use-common-state-another-way x state)))
I ended up making a macro that generates the following:
(define foo null)
(define bar null)
(let ((state (create-common-state)))
(set! foo (lambda (x) (use-common-state-one-way x state)))
(set! bar (lambda (x) (use-common-state-another-way x state))))
That works, but it seems a little clunky. Is there a better way?
Thanks,
Jeff de Vries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090317/c1c3626e/attachment.html>