SlideShare a Scribd company logo
1 of 15
CMSC 471
LISP
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?
• On sunserver (CS) and gl machines, run
/usr/local/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
Why all those parentheses?
• Surprisingly readable if you indent properly (use
built-in Lisp editor in emacs!)
• Makes prefix notation manageable
• An expression is an expression is an expression,
whether it’s inside another one or not
•(+ 1 2)
•(* (+ 1 2) 3)
•(list (* 3 5) ‘atom ‘(list inside a list)
(list 3 4) ‘(((very) (very) (very) (nested
list))))
Lisp basics
• Lisp syntax: parenthesized prefix notation
• Lisp interpreter: read-eval-print loop
• Nested evaluation
• Preventing evaluation (quote and other
special forms)
• Forcing evaluation (eval)
–Allows us to evaluate code contained in a Lisp
variable!
Basic Lisp types
• Numbers (integers, floating-point, complex)
–27 -2 7.519
• Characters, strings (arrays of chars)
–#x #- #B
–“This is a string!”
• Symbols, which have property lists
–‘a ‘x ‘jon
• Lists (linked cells)
– Empty list: nil
–‘(a b c) ‘(2 3 jon)
–cons structure has car (first) and cdr (rest)
Built-in functions
• For numbers
–+ - * / incf decf
• A diversion: destructive functions
–(setf x 1)
–(setf y (+ x 1)) vs. (setf y (incf x))
• For lists
–car (first) cdr (rest) second third
fourth
–length nth
–cons append nconc list
–mapcar mapcan
–find remove remove-if
Built-in functions (cont’d)
• Printing: print, format
– (print “string”)  print output
– (format …)  formatted output
• Advanced list processing: assoc, mapcar
• Predicates: listp, numberp, stringp,
atom, null, equal, eql, and, or, not
• Special forms: setq/setf, quote, defun,
defparameter, defconstant, if, cond,
case, progn, loop
More Lisp types
• Arrays (with zero or more dimensions)
• Hash tables
• Streams (for reading and writing)
• Structures
• Functions, including lambda functions
–(defun incBy10 (n) (+ n 10))
–(mapcar #’(lambda (n) (+ n 10))
‘(1 2 3 4 5))
Useful help facilities
•(apropos ‘str)  list of symbols whose
name contains ‘str
•(describe ‘symbol)  description of
symbol
•(describe #’fn)  description of function
•(trace fn)  print a trace of fn as it runs
•:a  abort one level out of debugger
A Lisp example
• Writing a function to compute the nth
Fibonacci number
–Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, …
• fib(0) = 0
• fib(1) = 1
• fib(n) = fib(n-2) + fib(n-1)
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))))))
Complete Version with Error
Checking and Comments
(defun fib (n)
"Computes the nth Fibonacci number."
(cond ((or (not (numberp n)) (< n 0)) ;error case
(error "~s must be a number >= 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))))))
Now you’ve been enlightened!
…well, sort of…
Cartoon from xkcd.com

More Related Content

Similar to LISP.ppt

AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxprakashvs7
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneJames Long
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTWAdriano Bonat
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To LispLISP Content
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Skills Matter
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersDiego Freniche Brito
 
Introduction to Functional Programming with Clojure
Introduction to Functional Programming with ClojureIntroduction to Functional Programming with Clojure
Introduction to Functional Programming with ClojureWilton Silva
 
Programming_Language_Syntax.ppt
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.pptAmrita Sharma
 
Topic01 intro.post
Topic01 intro.postTopic01 intro.post
Topic01 intro.postSree Devi
 
Scheme Programming Language
Scheme Programming LanguageScheme Programming Language
Scheme Programming LanguageReham AlBlehid
 
Clojure from ground up
Clojure from ground upClojure from ground up
Clojure from ground upDi Xu
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and FuturePushkar Kulkarni
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
cs241-f06-final-overview
cs241-f06-final-overviewcs241-f06-final-overview
cs241-f06-final-overviewColin Bell
 

Similar to LISP.ppt (20)

Lecture 2 lisp-Overview
Lecture 2 lisp-OverviewLecture 2 lisp-Overview
Lecture 2 lisp-Overview
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
 
Lisp
LispLisp
Lisp
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
Elixir introd
Elixir introdElixir introd
Elixir introd
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
Introduction to Functional Programming with Clojure
Introduction to Functional Programming with ClojureIntroduction to Functional Programming with Clojure
Introduction to Functional Programming with Clojure
 
Programming_Language_Syntax.ppt
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.ppt
 
Topic01 intro.post
Topic01 intro.postTopic01 intro.post
Topic01 intro.post
 
Scheme Programming Language
Scheme Programming LanguageScheme Programming Language
Scheme Programming Language
 
Clojure from ground up
Clojure from ground upClojure from ground up
Clojure from ground up
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and Future
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
cs241-f06-final-overview
cs241-f06-final-overviewcs241-f06-final-overview
cs241-f06-final-overview
 
Clojure intro
Clojure introClojure intro
Clojure intro
 

Recently uploaded

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

LISP.ppt

  • 2. 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
  • 3. Great! How can I get started? • On sunserver (CS) and gl machines, run /usr/local/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
  • 4. Why all those parentheses? • Surprisingly readable if you indent properly (use built-in Lisp editor in emacs!) • Makes prefix notation manageable • An expression is an expression is an expression, whether it’s inside another one or not •(+ 1 2) •(* (+ 1 2) 3) •(list (* 3 5) ‘atom ‘(list inside a list) (list 3 4) ‘(((very) (very) (very) (nested list))))
  • 5. Lisp basics • Lisp syntax: parenthesized prefix notation • Lisp interpreter: read-eval-print loop • Nested evaluation • Preventing evaluation (quote and other special forms) • Forcing evaluation (eval) –Allows us to evaluate code contained in a Lisp variable!
  • 6. Basic Lisp types • Numbers (integers, floating-point, complex) –27 -2 7.519 • Characters, strings (arrays of chars) –#x #- #B –“This is a string!” • Symbols, which have property lists –‘a ‘x ‘jon • Lists (linked cells) – Empty list: nil –‘(a b c) ‘(2 3 jon) –cons structure has car (first) and cdr (rest)
  • 7. Built-in functions • For numbers –+ - * / incf decf • A diversion: destructive functions –(setf x 1) –(setf y (+ x 1)) vs. (setf y (incf x)) • For lists –car (first) cdr (rest) second third fourth –length nth –cons append nconc list –mapcar mapcan –find remove remove-if
  • 8. Built-in functions (cont’d) • Printing: print, format – (print “string”)  print output – (format …)  formatted output • Advanced list processing: assoc, mapcar • Predicates: listp, numberp, stringp, atom, null, equal, eql, and, or, not • Special forms: setq/setf, quote, defun, defparameter, defconstant, if, cond, case, progn, loop
  • 9. More Lisp types • Arrays (with zero or more dimensions) • Hash tables • Streams (for reading and writing) • Structures • Functions, including lambda functions –(defun incBy10 (n) (+ n 10)) –(mapcar #’(lambda (n) (+ n 10)) ‘(1 2 3 4 5))
  • 10. Useful help facilities •(apropos ‘str)  list of symbols whose name contains ‘str •(describe ‘symbol)  description of symbol •(describe #’fn)  description of function •(trace fn)  print a trace of fn as it runs •:a  abort one level out of debugger
  • 11. A Lisp example • Writing a function to compute the nth Fibonacci number –Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, … • fib(0) = 0 • fib(1) = 1 • fib(n) = fib(n-2) + fib(n-1)
  • 12. 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))))))
  • 13. 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))))))
  • 14. Complete Version with Error Checking and Comments (defun fib (n) "Computes the nth Fibonacci number." (cond ((or (not (numberp n)) (< n 0)) ;error case (error "~s must be a number >= 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))))))
  • 15. Now you’ve been enlightened! …well, sort of… Cartoon from xkcd.com