[plt-scheme] accessing a top-level variable whose name is stored in a global variable

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Jul 26 13:45:51 EDT 2009


I don't understand from this email why a data structure,
possibly implemented via a class, of a collection of racks
wouldn't do the trick for your program. Why do you want to
have both a symbolic name for a rack _and_ a variable name?

-- Matthias




On Jul 26, 2009, at 2:52 AM, Gregg Williams wrote:

> Hi--My question has to do with how to accomplish indirection in
> Scheme--in particular, in the following (slightly simplified)
> function:
>
> (define (infoml:get-card-from-active-rack n)
>   (list-ref (eval *infoml:active-rack-name*) n))
>
> My intent is this. A "rack" is a named list defined at the top level,
> and my program has exactly one active rack. You guessed it, its name
> is stored in *infoml:active-rack-name*. In my code, I create a rack
> named decision-making as follows:
>
> (define decision-making (infoml:make-rack 'decision-making))
>
> In addition to defining a rack (i.e., a list) named decision-making,
> it also stores the value of the symbol 'decision-making in the global
> variable *infoml:active-rack-name*.
>
> What I'm trying to do with infoml:get-card-from-active-rack is to
> return the n'th item from the currently active rack--in this case, the
> n'th item in the rack/list named decision-making. At first, I wrote a
> function like this:
>
> (define (infoml:get-card-from-active-rack n)
>   (list-ref *infoml:active-rack-name* n))
>
> ... but that certainly didn't work. I read a lot of the PLT Scheme
> documentation but couldn't find anything that allowed me the
> indirection that I wanted. The documentation on eval was particularly
> forbidding, but I tried it anyway...and it seems to work!
>
> However, at the end of my program (which *is* giving me the correct
> output), I get the following error message:
>
> compile: unbound identifier (and no #%top syntax transformer is bound)
> in: decision-making
>
> I'd appreciate any insights on what would be a good way to accomplish
> what I'm trying to do. I'm not expecting any lengthy explanations, but
> pointing me to the right PLT Scheme documentation would be entirely
> sufficient. Thanks.
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.