August 19, 2024

P02 - Find the last but one box of a list

- Example:* (my-but-last '(a b c d))(C D)

lisp

(defun penultimo (list)
  (let ((reverse (reverse list)) ; puts in reverse variable the
					; reverse list
    (cond
     ((null reverse) nil)
     ;; if the list has 2 or fewer elements, return to own
     ((<= (reverse length) 2)The list)
     ;; if it has more than 2 elements, I build a list
     (t (list (second reverse) (first reverse))
     )
    )
  )
Be first to comment
Leave a reply