Difficulty: Easy
Correct Answer: returns the length of
Explanation:
Introduction / Context: Lisp lists and list-processing functions are foundational for AI and symbolic programming. The function list-length is used to determine how many cons cells are in a proper list. Knowing precisely what it returns prevents confusion with predicates or list-copying utilities.
Given Data / Assumptions:
Concept / Approach: In Common Lisp, list-length computes the number of elements in a proper list and returns an integer. It is not a predicate (it does not return t/nil based solely on emptiness) and does not produce a new copy of the list. Predicates like null check for emptiness, and functions such as copy-list duplicate lists.
Step-by-Step Solution: Identify the function’s role: measure cardinality of a list.Recall: (list-length nil) returns 0, not t.Confirm that no new list structure is created; only a count is computed.Therefore, it returns the length as an integer.
Verification / Alternative check: Evaluate examples: (list-length '(a b c)) → 3; (list-length nil) → 0. This verifies the behavior and differentiates it from predicates and copying functions.
Why Other Options Are Wrong: Copy list: behavior of copy-list, not list-length.
Returns t if empty: that is null, not list-length. All of the above: mixes mutually exclusive behaviors. None of the above: incorrect because returning the length is correct.Common Pitfalls: Confusing truthy/falsey values with numeric counts, and forgetting that an empty list has length 0 rather than returning a boolean.
Final Answer: returns the length of
Discussion & Comments