I agree with Robby's explanation on just the `compile` line. When you uncomment both lines, it's the same error as as
> (module m racket/base (define x 5)) > (require 'm) > (module m racket/base (define x 5)) define-values: assignment disallowed; cannot re-define a constant constant: x in module: 'm After you instantiate a module in a given namespace, you can't redefine or otherwise mutate that module's immutable variables in the same namespace. (The absence of any `set!` in the original module means that `x` is immutable.) Granted, the new value would be the same as the old one in this case, so `x` wouldn't actually change, but redefinition is disallowed anyway. If you really want to declare a module multiple times, then you can set `compile-enforce-module-constants` to #f: > (compile-enforce-module-constants #f) > (module m racket/base (define x 5)) > (require 'm) > (module m racket/base (define x 5)) ; no error At Fri, 25 Dec 2015 15:34:20 -0600, Robby Findler wrote: > Well, considering my past performance you definitely don't want to to > trust me on these questions, but I'll give it a try anyway. :) > > My guess is that when you comment in only this line from the last two: > > (eval (compile prog)) > > then the "x" is compiled into a reference to a top-level variable, not > a reference to the variable exported from the module "foo" because > compile compiles the whole expression at once, and so it doesn't seem > that there's now a module export that it should compile the top-level > variable "x" into. > > Similarly, the first expression in the module just below produces 1 > and the second one produces an error. > > #lang racket > > (parameterize ([current-namespace (make-base-namespace)]) > (define xc (compile #'x)) > (eval '(define x 1)) > (eval xc)) > > (parameterize ([current-namespace (make-base-namespace)]) > (define xc (compile #'x)) > (eval '(module m racket/base (define x 1) (provide x))) > (eval '(require 'm)) > (eval xc)) > > Robby > > > On Fri, Dec 25, 2015 at 3:00 PM, Leif Andersen <l...@leifandersen.net> wrote: > > I should probably also mention that if I comment out the first eval > > leaving only `(compile (eval prog))`, I get: > > > > x: undefined; > > cannot reference undefined identifier > > > > > > Which leads me to think that the other error is from trying to require > > the same module twice in the same namespace. > > > > > > But I'm still not sure what the cause of the other issue is though. > > > > ~Leif Andersen > > > > > > On Fri, Dec 25, 2015 at 11:18 AM, Leif Andersen <l...@leifandersen.net> > wrote: > >> Hey, I have found another bit of confusion between eval and compile. > >> Again, I suspect it's related to using a top level begin, but I'm not > >> sure why. > >> > >> I have the following program: > >> #lang racket > >> > >> (define prog #'(begin > >> (module foo racket > >> (#%plain-module-begin > >> (provide x) > >> (define x 5))) > >> (require 'foo) > >> x)) > >> ; (eval prog) > >> ; (eval (compile prog)) > >> > >> When I uncomment the first line to run `(eval prog)` the program runs fine. > >> > >> However, when I uncomment the second line to run `(eval (compile > >> prog))`, I get the following error: > >> > >> define-values: assignment disallowed; > >> cannot re-define a constant > >> constant: x > >> > >> Also, when I use syntax/toplevel and add the following line: > >> `(eval (compile (expand-syntax-top-level-with-compile-time-evals prog)))` > >> I get the same error. > >> > >> Can you give me some intuition as to what the problem is here? > >> > >> ~Leif Andersen > > > > -- > > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.