Hi all - <br><br>Tying together what I&#39;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).&nbsp; 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?&nbsp; Making dispatcher a parameter object doesn&#39;t seem to be of help either.&nbsp; Basically the code has the following: 
<br><br>1) dispatcher as a hash-table <br>2) register &amp; 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>&nbsp; <br>&nbsp; (define dispatcher (make-parameter (make-hash-table &#39;equal))) ; run-time dispatcher...  
<br>&nbsp; <br>&nbsp; (define-syntax (register stx)  <br>&nbsp;&nbsp;&nbsp; (syntax-case stx () <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((_ key value) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(hash-table-put! dispatcher key value)))) <br>&nbsp; <br>&nbsp; (define-syntax (dispatch stx)&nbsp;  <br>&nbsp;&nbsp;&nbsp; (syntax-case stx () 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((_ key args ...) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;((hash-table-get dispatcher key) args ...)))) <br>&nbsp; <br>&nbsp; (define-syntax (define-action stx) <br>&nbsp;&nbsp;&nbsp; (syntax-case stx () <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((_ (name arg1 ...) body ...) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #`(begin (define (name arg1 ...) 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; body ...) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (register (quote name) name)))))<br>&nbsp; <br>&nbsp; (provide register <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dispatch <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dispatcher <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; define-action)) <br><br>(module bar mzscheme 
<br>&nbsp; (require foo)<br>&nbsp; (define-action (test a b) (+ a b)) <br>&nbsp; (display (test 1 2)) <br>&nbsp; (display (dispatch &#39;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...