15 lines
321 B
Common Lisp
15 lines
321 B
Common Lisp
(defun my-last (lst)
|
|
"Return the last element of the list LST."
|
|
(cond
|
|
((null lst) nil)
|
|
((null (cdr lst)) (car lst))
|
|
(t (my-last (cdr lst)))))
|
|
|
|
;; Native implementation
|
|
;; (last lst)
|
|
|
|
;; C-c C-k
|
|
(assert (equal (my-last '()) nil))
|
|
(assert (equal (my-last '(a)) 'a))
|
|
(assert (equal (my-last '(a b c d)) 'd))
|