階乗計算プログラム

(defun fact (n)
  (cond ((= n 0) 1)
	(t (* n (fact (- n 1))))))
fact

(fact 5)
120


整列化プログラム

(defun sort (L)
  (cond ((null L) ())
	(t (insert (car L) (sort (cdr L))))))
sort

(defun insert (x L)
  (cond ((null L) (cons x ()))
	((<= x (car L)) (cons x L))
	(t (cons (car L) (insert x (cdr L))))))
insert

(sort '(34 84 92 1 92 7 34))
(1 7 34 34 84 92 92)


ハノイの塔

(defun hanoi (n from to work)
  (cond ((= n 0) t)
	(t (hanoi (- n 1) from work to)
	   (progn (princ from) (princ '\ ->\ ) (princ to) (terpri))
	   (hanoi (- n 1) work to from))))
hanoi
(hanoi 3 1 3 2)
1 -> 3
1 -> 2
3 -> 2
1 -> 3
2 -> 1
2 -> 3
1 -> 3
t
(hanoi 4 'from 'to 'work)
from -> work
from -> to
work -> to
from -> work
to -> from
to -> work
from -> work
from -> to
work -> to
work -> from
to -> from
work -> to
from -> work
from -> to
work -> to
t