In Common LISP programming, which built-in predicate returns t if <integer> is even and nil otherwise (assume <integer> is an exact integer object)?

Difficulty: Easy

Correct Answer: (evenp )

Explanation:


Introduction / Context:
Common LISP provides a rich set of numeric predicates for testing properties of numbers. Knowing the idiomatic names of these predicates is important for writing readable, conventional LISP code and for understanding legacy AI codebases that rely on LISP macros and functions.


Given Data / Assumptions:

  • Language: Common LISP.
  • Input is an exact integer.
  • We need the standard predicate that tests parity.


Concept / Approach:
The canonical predicates for parity in Common LISP are evenp and oddp. The suffix “p” conventionally marks a predicate returning t or nil. There is no standard predicate named even, and fabricated names like numeven or numnevenp are not part of the standard.


Step-by-Step Solution:

Recall Common LISP naming conventions: predicates often end with “p”. Identify parity test: evenp → returns t for even integers, nil otherwise. Eliminate non-standard or misspelled alternatives. Choose (evenp <integer>).


Verification / Alternative check:
Common LISP HyperSpec documents evenp and oddp as standard numeric predicates for integers, confirming the choice.


Why Other Options Are Wrong:

  • (even <integer>): not a standard predicate.
  • (numeven <integer>), (numnevenp <integer>): invented names.
  • None: incorrect because (evenp <integer>) is correct.


Common Pitfalls:
Forgetting the “p” suffix for predicates in LISP; confusing Common LISP with Scheme function names.


Final Answer:
(evenp <integer>)

More Questions from Artificial Intelligence

Discussion & Comments

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