Difficulty: Easy
Correct Answer: (numberp
Explanation:
Introduction / Context:
Lisp provides a rich set of predicates to test the type and properties of objects at runtime. Choosing the correct predicate prevents subtle bugs and clarifies intent in programs that manipulate heterogeneous data structures.
Given Data / Assumptions:
Concept / Approach:
In Common Lisp, predicates often end with the character p, indicating a question function that returns a boolean-like value. The standard numeric predicate is numberp
. Variants like integerp
and floatp
exist for narrower categories. Names such as numericp
or numeric
are not standard predicates in Common Lisp, and (number
would be parsed as a function call to a symbol number, not a built-in predicate.
Step-by-Step Solution:
(numberp
as the correct choice.
Verification / Alternative check:
In a REPL, (numberp 3)
and (numberp 3.14)
both yield t, while (numberp 'abc)
yields nil, confirming correctness.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing Scheme or other dialect naming with Common Lisp conventions; forgetting more specific predicates like integerp when needed.
Final Answer:
(numberp
Discussion & Comments