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

From: Gregg Williams (spamme at innerpaths.net)
Date: Sun Jul 26 02:52:40 EDT 2009

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.


Posted on the users mailing list.