In example code in a book I'm reading, there's a line for a macro that provides shorthand for getting the global value of a symbol:
(defmacro sv (v) '(symbol-value `,v))
However, Allegro sees V as an unbound variable. I don't know how to change this macro to return the correct result, because I've never encountered a problem like this before. How would I get the global value of any symbol? Thanks for your help!
You need a backquote, not a single quote, in front of the whole s-exp:
(I know, it's hard to see: Just move the backquote in your original s-exp from in front of
,vand replace the single quote at the beginning of'(symbol-value ...)).Backquote operates on expressions (lists), not individual atoms, per se. If what you typed was actually in the book, it's likely an erratum.
A slightly better version of
sv:or
In the last version, interchange the backquote and single quote in your original code. The penultimate version just makes it easier to read.
However,
symbol-valueonly queries the current value bound to the variable. For example, this code evaluates to'something-else:The
*wombat*in theletform is a lexical variable, whereas the*wombat*in thedefparameterform is dynamic. Theletform temporarily hides the visibility of thedefparameter.