[plt-scheme] cannot modify module-bound variables

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 16 20:57:37 EDT 2007

At Mon, 16 Apr 2007 16:30:36 -0700, "Yin-So Chen" wrote:
>   (define dispatcher (make-parameter (make-hash-table 'equal))) ; run-time
> dispatcher...

`make-parameter' returns a value that acts like a procedure.

>   (define-syntax (register stx)
>     (syntax-case stx ()
>       ((_ key value)
>        #'(hash-table-put! dispatcher key value))))

Use `(dispatcher)' instead of `dispatcher' to get the current dispatcher.

>   (define-syntax (dispatch stx)
>     (syntax-case stx ()
>       ((_ key args ...)
>        #'((hash-table-get dispatcher key) args ...))))

Same here.

> (require bar) ; error = define-values: cannot change identifier that is
> instantiated as a module constant: dispatcher

I get a different result:

 hash-table-put!: expects type <mutable hash-table> as 1st argument,
 given: #<primitive:parameter-procedure>; other arguments were: test

For your error:

I think you must be using raw mzscheme and trying to re-define the
`dispatcher' module (as opposed to, say, using DrScheme with its "Run"
button that clears out old state before running program). 

Re-defining a module conflicts with certain optimizations that you'd
normally like the compiler to perform. To disable the optimizations and
allow module re-definition, use `(compile-enforce-module-constants


Posted on the users mailing list.