Search code examples
lispwarningsclisp

LISP car of the last element?


LISP stumps me yet again... Why can't I get the value of the last element in a list? I have a list set up similar to this:

(setq bar '(((1 2) 3 4 5)((6 7) 8 9 10)))

Now I get a return of 4 for:

(caddar bar)

There is a return of (5) for:

(cdddar bar)

But I can't get a 5 for:

(cadddar bar)

Why is this--and how do I get the value of the 5?

Error:

; Warning: This function is undefined:
;   CADDDAR

Error in KERNEL:%COERCE-TO-FUNCTION:  the function CADDDAR is undefined.
[Condition of type UNDEFINED-FUNCTION]

Solution

  • The functions with 5 or more a's and d's are not defined. Only 4 and fewer. There are too many possible functions of that length for it be be practical.

    You have to just spell it out: (car (cdr (cdr (cdr (cdr (car x))))))