Difficulty: Easy
Correct Answer: set
Explanation:
Introduction / Context:
In Common Lisp, variable assignment can be done with multiple forms. Understanding when the variable name is evaluated versus treated as a literal symbol is crucial, especially for indirect assignments and metaprogramming tasks.
Given Data / Assumptions:
set
and setq
semantics.
Concept / Approach:setq
assigns to a named variable without evaluating the variable name; only the value expression is evaluated. By contrast, set
evaluates its first argument to obtain a symbol and evaluates its second argument for the new value. Thus, set
supports indirect assignment when the symbol to assign is itself computed.
Step-by-Step Solution:
set
.Select ‘‘set’’ as the correct choice.
Verification / Alternative check:
Test in a REPL: (let ((s 'x')) (set (symbol-value 's') 5)) demonstrates evaluated first arg; (setq s 5) would instead set variable s, not X.
Why Other Options Are Wrong:
setq
does not evaluate the variable name.add
and ‘‘eva’’ are not standard Common Lisp assignment primitives.
Common Pitfalls:
Passing a raw symbol to set
without quoting or ensuring evaluation yields a symbol leads to errors; ensure the first argument evaluates to a symbol object.
Final Answer:
set
Discussion & Comments