Jotter <2026-03-16 Mon>
(let ((x 3))
(let ((x 4))
(print x))
(print x))
(cons 'a ()) ; => (A)
(append '(a b c) '(d e f)) ; => (A B C D E F)
(cons 'a '(b c d)) ; => (A B C D)
(cons 3 '(4 1 2)) ; => (3 4 1 2)
(max 3 4) ;; => 4
(max 2 5 1 3 6) ;; => 6
;; Find the largest number in a list of numbers.
(defun test-max-numbers ()
(and (= 3 (max-numbers '(1 2 3)))
(= 1 (max-numbers '(1 1 1)))
;; (= nil (max-numbers ()))
(= 1 (max-numbers '(1)))
(= 366 (max-numbers '(-365 0 366 5)))
(= -365 (max-numbers '(-365 -366)))))
(defun max-numbers (ns)
"Find the largest number in a list of numbers."
(cond ((null ns) (error "List can not be empty"))
((= 1 (length ns)) (first ns))
(t (max (first ns)
(max-numbers (rest ns))))))
(test-max-numbers)
;; Return the list of numbers with elements which are
;; double those of the input list.
(= 3 4)
(= 3 (+ 1 2))
(equal '(a b c) '(a b c))
(equal '(a b c) '(a b c d))
(defun test-doubles ()
(and (equal () (doubles ()))
(equal '(2) (doubles '(1)))
(equal '(2 4 6 8) (doubles '(1 2 3 4)))))
(defun doubles (ns)
"Return a list of the doubles of the input list of numbers"
(cond ((null ns) ())
((consp ns) (cons (* 2 (first ns))
(doubles (rest ns))))))
(test-doubles)
Author: Breanndán Ó Nualláin
Created: 2026-03-16 Mon 17:40
Validate