Difficulty: Easy
Correct Answer: (setq b a)
Explanation:
Introduction / Context:
Understanding assignment syntax is essential in Lisp, which uses prefix notation and special forms for variable binding and mutation. The task is to set variable b
to the value currently held in a
.
Given Data / Assumptions:
b
has the same value as a
.
Concept / Approach:
The special form setq
performs assignment using the pattern (setq var value)
. Therefore, (setq b a)
copies the value of a
into b
. Forms like (b = a)
or (set b = a)
reflect C-like or pseudo-code syntax and are invalid in Lisp. (setq a b)
would reverse the assignment direction, setting a
to b
, not vice versa.
Step-by-Step Solution:
setq
.Apply the correct argument order: destination first (b), then source value (a).Select (setq b a)
.
Verification / Alternative check:
In a REPL: set a
first (e.g., (setq a 42)
), then evaluate (setq b a)
; now b
evaluates to 42.
Why Other Options Are Wrong:
(setq b a)
is correct.
Common Pitfalls:
Mixing up setq
versus local binding with let
, and reversing source/destination order.
Final Answer:
(setq b a)
Discussion & Comments