Common Lisp predicate basics: which function returns t when and only when the provided object is a symbol?

Computer Science Artificial Intelligence Difficulty: Easy
Choose an option
  • A
    (* <object>)
  • B
    (symbolp <object>)
  • C
    (nonnumeric <object>)
  • D
    (constantp <object>)
  • E
    None of the above

Answer

Correct Answer: (symbolp <object>)

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:

  • The dialect is Common Lisp.
  • Predicates often end with p and return t or nil.
  • We need a general test for “is this value a symbol?”

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:

Identify candidate predicates that match Common Lisp naming conventions.Recall that 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:

(* ): multiplication operator, not a type test.(nonnumeric ): not a standard CL predicate.(constantp ): tests constant forms, not symbol-ness.None of the above: incorrect because symbolp is correct.

Common Pitfalls: Confusing symbol tests with string or keyword tests; remember keywords are symbols too.

Final Answer: (symbolp )

Discussion & Comments
No comments yet. Be the first to comment!
Join Discussion