CS 63 CS 63 LISP LISP Philip Greenspun's Tenth* Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp.“ * Note: there aren’t actually nine other rules, just the tenth one.
15
Embed
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CS 63CS 63
LISPLISPPhilip Greenspun's Tenth* Rule of Programming:"Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp.“
* Note: there aren’t actually nine other rules, just the tenth one.
Something I stumbled across…
“…teaching Lisp by showing you how to write several complete Lisp-based games, including a text adventure, an evolution simulation, and a robot battle.”
Disclaimer: I’m not endorsing this book, I just liked the cover.
Why Lisp?
• Because it’s the most widely used AI programming language
• Because it’s good for writing production software (Graham article)
• Because it’s got lots of features other languages don’t
• Because you can write new programs and extend old programs really, really quickly in Lisp
Great! How can I get started?
• Run /usr/bin/clisp
• From http://clisp.cons.org you can download CLISP for your own PC (Windows or Linux)
• Great Lisp resource page: http://www.apl.jhu.edu/~hall/lisp.html
Complete Version(defun fib (n) (cond ((eql n 0) 0) ; base case ((eql n 1) 1) ; base case (t (+ (fib (- n 1)) ; recursively compute fib(n) (fib (- n 2))))))
Complete Version with Error Checking and Comments
(defun fib (n) "Computes the nth Fibonacci number." (cond ((or (not (integerp n)) (< n 0)) ; error case (error "~s must be an integer >= 0.~&" n)) ((eql n 0) 0) ; base case ((eql n 1) 1) ; base case (t (+ (fib (- n 1)) ; recursively compute fib(n) (fib (- n 2))))))