In Common Lisp, which form evaluates the value expression and assigns that value to the (unevaluated) symbol to create a named constant?
-
A(constant <sconst> <object>)
-
B(defconstant <sconst> <object>)
-
C(eva <sconst> <object>)
-
D(eva <object> <sconst>)
-
ENone of the above
Answer
Correct Answer: (defconstant <sconst> <object>)
Explanation
Introduction / Context: Common Lisp has several defining forms for variables and constants. When you need to bind a symbol to a value that should not change (i.e., a constant), you use the defconstant form. It takes the symbol name (not evaluated) and an initializing form (evaluated) whose resulting value becomes the constant’s value.
Given Data / Assumptions:
- The symbol (name) should be treated as an unevaluated identifier.
- The value expression should be evaluated, and that value assigned.
- We are specifically creating a constant, not a special/dynamic variable.
Concept / Approach: The form (defconstant name value-form) defines name as a global constant. The name is a symbol, not evaluated; the value-form is evaluated at definition time, and the result is stored. Afterward, redefining may be implementation-dependent or produce warnings because constants are meant to be stable. Other forms in the options are either non-existent in Common Lisp or do not match the semantics described.
Step-by-Step Solution:
Identify the required behavior: evaluate the value form, not the symbol.Map to Common Lisp defining forms: defconstant, defparameter, defvar.Select defconstant because the question explicitly references an “unevaluated symbol” receiving the evaluated value and being a constant.Eliminate non-standard or incorrect forms.Verification / Alternative check: In a Lisp REPL, (defconstant +pi+ 3.14159) defines a constant. The symbol +pi+ is not evaluated as a variable at read time; it is used as a name. The numeric literal is evaluated to itself and stored as the constant value.
Why Other Options Are Wrong:
- (constant ...): not a standard defining form.
- (eva ...): not a Common Lisp form; “eval” is different and not used like this.
- None of the above: incorrect because defconstant matches exactly.
Common Pitfalls: Confusing defconstant with defparameter (which allows reassignment) or defvar (which initializes only if unbound). Misunderstanding evaluation: symbol names in defining forms are not evaluated.
Final Answer: (defconstant <sconst> <object>)