[plt-scheme] Interactions in the Module language
At Tue, 20 Jan 2009 10:25:25 -0500, Prabhakar Ragde wrote:
> We covered mutation today in lecture. I had not done this before using
> the Module language. Afterwards, a student came up and showed me this
> interesting phenomenon.
>
> In the Definitions window:
>
> #lang scheme
>
> (define a 1)
> (set! a 2)
> (define b 1)
>
> In the Interactions window:
>
> > (set! a 3)
> > a
> 3
> > (set! b 2)
> set!: cannot modify a constant: b
>
> Now, I know the top level is hopeless, and I have an intuitive
> explanation, which is that in the analysis of the module in the
> Definitions window, b has been optimized down to a constant but a has
> not.
Any definition that is not `set!'ed within the module is considered
constant --- which, of course, may enable optimizations, but
constantness doesn't depend on an optimization occurring.
> Is there a more accurate explanation, and does a prediction of this
> exist in Help Desk?
It looks like this information is missing from the specification of
`module', so I'll fix that.
Also, I thought that Section 6.6 of the Guide would talk about it
(http://docs.plt-scheme.org/guide/module-set.html), but the information
is missing there, too.
> I note the parameter
> `compile-enforce-module-constants', whose explanation seems to have some
> bearing,
Indeed, that seems to be the only place that module-variable
constantness is currently defined (which is not nearly good enough).
> but the parameter seems to have value #f in the Interactions
> window, and I cannot get it to do anything useful in this example.
I imagine that the parameter is set after the module is evaluated, but
I'm not sure why it would be set at all unless it was meant to be set
before compiling the module. I'll investigate further. Meanwhile, I
don't think there's a way to parameter within the module.
Matthew