[racket] #%top and hopeless toplevel stuff

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Wed Aug 25 20:50:34 EDT 2010

And, just to be clear, you can look at the code in rep.rkt to see what
DrRacket does (altho it is pretty complex; there are a lot of cases).

It might help to know that the module-based language case is a fairly
simple case and that for other cases, probably the right thing is to
make the sandbox do the right thing and use it (I think).


On Wed, Aug 25, 2010 at 6:52 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> I wanted to make sure I understand how toplevel variables, REPLs and
> namespaces work.  I need to understand this because what I'm doing in
> WeScheme's REPL is not quite right because it doesn't match what is
> happening with DrRacket's REPL.
> I see that the error messages regarding toplevel variables are
> slightly different, depending on context.  e.g. set! can produce
> either the error message
>    set!: unbound identifier in module in: x
> or the message:
>    set!: cannot set undefined variable: x
> depending on the compilation context.  Furthermore, from talking with
> Carl Eastlund, I understand that interactions do something with
> namespaces when hitting toplevel variables.  The following transcript
> confirms to me that toplevel variable lookup and set! cooperates with
> namespaces, at least at the REPL:
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> my-unbound-variable
> reference to undefined identifier: my-unbound-variable
>> (set! x 16)
> set!: cannot set undefined variable: x
>> (namespace-set-variable-value! 'my-unbound-variable "hello world")
>> my-unbound-variable
> "hello world"
>> (set! my-unbound-variable 'ok)
>> my-unbound-variable
> 'ok
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> I'm trying to understand what's happening.  How does set! know in what
> context (definitions or interactions) it is being used?  What in the
> documentation should I be looking at to better understand this?
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.