Hi all - <br><br>Tying together what I've learned so far I ran into problems trying to create a function dispatcher without having the client aware of the existence of the dispatch table (implemented as a hash-table). The code works until I try to abstract the functionality to reside in a module, at which I get the following error:
<br><br><div style="margin-left: 40px;">define-values: cannot change identifier that is instantiated as a module constant: dispatcher<br></div><br>How can I get around this problem? Making dispatcher a parameter object doesn't seem to be of help either. Basically the code has the following:
<br><br>1) dispatcher as a hash-table <br>2) register & dispatch macros that hides the existence of the dispatcher <br>3) define-action that wraps around creating a function and register the function with the dispatcher (
i.e. without the client having to manual register) <br><br>Below is the code in question... <br><br>(module foo mzscheme <br> <br> (define dispatcher (make-parameter (make-hash-table 'equal))) ; run-time dispatcher...
<br> <br> (define-syntax (register stx) <br> (syntax-case stx () <br> ((_ key value) <br> #'(hash-table-put! dispatcher key value)))) <br> <br> (define-syntax (dispatch stx) <br> (syntax-case stx ()
<br> ((_ key args ...) <br> #'((hash-table-get dispatcher key) args ...)))) <br> <br> (define-syntax (define-action stx) <br> (syntax-case stx () <br> ((_ (name arg1 ...) body ...) <br> #`(begin (define (name arg1 ...)
<br> body ...) <br> (register (quote name) name)))))<br> <br> (provide register <br> dispatch <br> dispatcher <br> define-action)) <br><br>(module bar mzscheme
<br> (require foo)<br> (define-action (test a b) (+ a b)) <br> (display (test 1 2)) <br> (display (dispatch 'test 1 2))) <br><br>(require bar) ; error = define-values: cannot change identifier that is instantiated as a module constant: dispatcher
<br><br>Thanks,<br>yinso <br><br>-- <br><a href="http://www.yinsochen.com">http://www.yinsochen.com</a><br>...continuous learning...