In Common Lisp, evaluate the expression and predicate: What is the result of (minusp (- 20 4 8 8 1)) ?

Difficulty: Easy

Correct Answer: T

Explanation:


Introduction / Context:
Common Lisp provides arithmetic operators and numeric predicates that return truth values. The function minusp tests whether a number is strictly less than zero. This question combines arithmetic evaluation with a predicate: you must first compute the numeric result of a subtraction expression and then apply minusp to that result.


Given Data / Assumptions:

  • Expression to evaluate is (- 20 4 8 8 1).
  • Predicate to apply is (minusp <number>), which returns T if <number> < 0, else NIL.
  • In Common Lisp, subtraction with multiple arguments computes left-associative subtraction: a - b - c - d ...


Concept / Approach:
Compute the inner arithmetic first, then use the predicate. Remember that T is Lisp’s canonical true value and NIL is false. Some Lisps also print NIL for false, not “F”. Therefore, the final answer must respect Lisp’s true/false conventions.


Step-by-Step Solution:

(- 20 4 8 8 1) → start with 20.20 - 4 = 16.16 - 8 = 8.8 - 8 = 0.0 - 1 = -1.Now evaluate (minusp -1) → is -1 < 0? Yes.Thus, (minusp (- 20 4 8 8 1)) returns T.


Verification / Alternative check:
You can verify in a REPL: evaluating the arithmetic yields -1, and (minusp -1) returns T. Testing a non-negative like 0 would return NIL because 0 is not negative in Lisp’s numeric predicates.


Why Other Options Are Wrong:

  • F: not a standard Lisp boolean; false is NIL.
  • NIL: would be correct only if the number were non-negative.
  • -20: confuses result with the original operand; the arithmetic result is -1, not -20.
  • None of the above: incorrect because T is correct.


Common Pitfalls:
Mis-evaluating multi-argument subtraction; assuming 0 is negative; confusing NIL with F; forgetting Lisp’s truth values and evaluation order (inner form first).


Final Answer:
T

More Questions from Artificial Intelligence

Discussion & Comments

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