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
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.