;;; THE INTRO TO AI SHOW ;;; Summer Session I 1999 ;;; ;;; DEMO: ;;; Collatz function ;;; ;;; NOTE: ;;; The function in question is defined in normal ;;; mathematical form in the class slides. ;;; ;;; Selmer Bringsjord ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; First, a simple example of loop. (defun enumerate-bringsjords () (let ((bringsjords '(thor carl conrad olga alexander katherine erik kurt pam))) (loop (when (endp bringsjords) (return 'done)) (print (first bringsjords)) (format t "is a very smart person.") (setf bringsjords (rest bringsjords))))) (defun enumerate-all-bringsjords () (enumerate-bringsjords) (format t "~%... But SELMER is an outright genius.")) ;;; Collatz's Problem used to show loop and then ;;; do-times. Is this a total function on the natural numbers? (defun mystery (n) (loop (print n) (when (or (equal 0 n) (equal 1 n)) (return n)) (if (evenp n) (setf n (/ n 2)) (setf n (+ 1 (* 3 n)))))) (defun mystery-loop (max) (dotimes (count max) (mystery count))) (with-open-file (random-stream "chaotic-nums2" :direction :output) (print (mystery-loop 5) random-stream))