In the LISP programming language used for AI, which built-in function returns the first element of a list structure (i.e., the head of the list)?

Difficulty: Easy

Correct Answer: car

Explanation:


Introduction / Context:
LISP is a classic AI programming language built around symbolic expressions (s-expressions) and list processing. Two primitive selectors, historically named car and cdr, retrieve parts of a list. Recognizing what each returns is essential for reading and writing idiomatic LISP code and for understanding many AI examples from classic literature.


Given Data / Assumptions:

  • The question focuses on the function that returns the first element of a list.
  • LISP lists are linked cells (cons pairs) where the head (car) holds the first element, and the tail (cdr) holds the rest.
  • Some dialects provide synonyms (e.g., first) but the canonical primitive is still car.


Concept / Approach:

In most LISP dialects, car(list) yields the head element. cdr(list) produces the tail (a list of remaining elements). While some dialects support first as a more readable alias, the primitive historically and portably recognized is car—originating from the hardware architecture of early Lisp machines ('contents of the address register').


Step-by-Step Solution:

Recall the pair of primitives: car → head, cdr → tail.Map the requested operation (first element) to car.Note that set is unrelated; second is a convenience function (or composition).Select 'car' as the correct answer.


Verification / Alternative check:

Running a simple example in any LISP REPL—e.g., (car '(a b c)) → a—confirms the behavior unambiguously.


Why Other Options Are Wrong:

set: Assignment or symbol binding in some dialects; not list selection.

first: Often a synonym, but traditionally the primitive asked in such questions is car.

second: Returns the second element or is defined via (car (cdr ...)).

None: Incorrect because car is standard.


Common Pitfalls:

Confusing dialect conveniences with core primitives; mixing up car and cdr semantics.


Final Answer:

car

More Questions from Artificial Intelligence

Discussion & Comments

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