Reputation: 2663
So (car '(2 3)) -> 2
(cdr '(2 3)) -> (3)
Which function should I use to be able to get something to yield 3?
(function-name '(2 3)) -> 3
Upvotes: 1
Views: 90
Reputation: 180918
Hints:
car
refers to the first element in the list.
cdr
refers to the remainder of the list, and is itself a list.
So what you need is a function that returns the first element from a list containing the last element.
Upvotes: 2
Reputation: 3719
It should be fine to simply do:
(car (cdr '(2 3)))
Which is the same as:
(cadr '(2 3))
This works because "car" gets the first element in the expression, whereas cdr returns the remainder of the list, without the first element. You've already shown that "(cdr '(2 3))" returns a list of "(3)". Therefore, the "car" of this is the element (not the list), "3". By the way, the "(cdr (cdr ('2 3)))" is the "(cdr (3))", which is "()".
Isn't LISP fun?
Upvotes: 7