Difficulty: Easy
Correct Answer: (symbolp
Explanation:
Introduction / Context:
Lisp code frequently inspects data types at runtime. Recognizing the correct predicate for symbols is fundamental, especially when manipulating code-as-data, macros, or abstract syntax trees where symbols serve as identifiers.
Given Data / Assumptions:
Concept / Approach:
The standard predicate for symbols is symbolp
. Alternatives listed either are not predicates of the right kind or test different properties: constantp
checks whether a form is a compile-time constant, while (*
is an arithmetic call, not a predicate. There is no standard nonnumeric
predicate in Common Lisp.
Step-by-Step Solution:
symbolp
returns t for symbols and nil otherwise.Select (symbolp
.
Verification / Alternative check:
In a REPL: (symbolp 'x)
→ t; (symbolp 42)
→ nil. This confirms the behavior.
Why Other Options Are Wrong:
symbolp
is correct.
Common Pitfalls:
Confusing symbol tests with string or keyword tests; remember keywords are symbols too.
Final Answer:
(symbolp
Discussion & Comments