Difficulty: Easy
Correct Answer: It returns t if the list is empty
Explanation:
Introduction / Context:
Lisp programmers frequently test for the end of a list while traversing structures. Common Lisp provides the predicate endp specifically for this purpose. Understanding how endp behaves clarifies robust list-processing patterns and prevents errors when handling dotted lists or non-list values.
Given Data / Assumptions:
endp is applied to a value expected to be a list.t as the canonical true value in Lisp.endp with other operations such as length and list copying.
Concept / Approach:
endp returns t when its argument is the empty list, and nil otherwise. It is intended for detecting the termination condition during recursion or iteration over lists. It does not copy lists, nor does it compute lengths. While null also tests for the empty list, endp is semantically tied to proper list termination and can signal an error for arguments that are not lists, which encourages cleaner list-processing code.
Step-by-Step Solution:
Verification / Alternative check:
In a REPL: (endp nil) evaluates to t, and (endp (list 1)) evaluates to nil, confirming the predicate behavior.
Why Other Options Are Wrong:
Common Pitfalls:
Using null on non-list values without checks; forgetting endp’s role in proper list termination tests.
Final Answer:
It returns t if the list is empty
Discussion & Comments