From: Frode Vatvedt Fjeld
Subject: dynamic symbol
Date: 
Message-ID: <2hwvr5clup.fsf@dslab7.cs.uit.no>
Is it possible to access a "variable" symbol as a dynamic variable?

What i mean is something like this, except NAME is not constant but
bound somewhere else:

(let ((name "foo")
      (foo 10))
  (symbol-value (intern name)))

..here SYMBOL-VALUE doesn't work because FOO is only lexically
bound. My question again is if I can make lisp use the symbol (here
FOO) as a dynamic variable. I can't simply insert (declare (special
foo)) because NAME could be bound to any string.

Thanks,
-- 
Frode Vatvedt Fjeld
From: Kent M Pitman
Subject: Re: dynamic symbol
Date: 
Message-ID: <sfwg0xt2qtq.fsf@world.std.com>
Frode Vatvedt Fjeld <······@acm.org> writes:

> Is it possible to access a "variable" symbol as a dynamic variable?
> 
> What i mean is something like this, except NAME is not constant but
> bound somewhere else:
> 
> (let ((name "foo")
>       (foo 10))
>   (symbol-value (intern name)))
> 
> ..here SYMBOL-VALUE doesn't work because FOO is only lexically
> bound. My question again is if I can make lisp use the symbol (here
> FOO) as a dynamic variable. I can't simply insert (declare (special
> foo)) because NAME could be bound to any string.

(defun tryme (name)
  (let ((symbol (intern name)))
    (progv (list symbol) (list 10)
      (symbol-value symbol))))

(tryme "FOO")
 => 10

PROGV is used for binding symbols (not names) as special variables,
when those symbol names are not known at compile time.
SYMBOL-VALUE is used for accessing symbols under like circumstances.