Friday, April 18, 2008


During my CSE321 class, the instructor showed us a "greatest common denominator" program in Python. If it weren't in Python, I would've written it in Python; however, it was, so I decided to do it in Lisp:


(defun gcd (x y) (if (= y 0) (x) (gcd y (mod x y))))
(setq x (first (rest si::*command-args*)))
(setq y (first (rest (rest si::*command-args*))))
(if (and x y) (progn
(setq x (parse-integer x))
(setq y (parse-integer y))
(format t "~D~%" (gcd x y))
% gcl -f gcd.l 128 104

This is the first moderately-useful Lisp program I've ever written, too.

Post a Comment