Lisp Basics and Idioms - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Lisp Basics and Idioms

Description:

... writes an algebraic list processing language for AI work ... Strongly tied to AI research during the 70s and 80s. Fell from prominence during the AI Winter ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 16
Provided by: peterchr
Category:
Tags: ai | basics | idioms | lisp

less

Transcript and Presenter's Notes

Title: Lisp Basics and Idioms


1
Lisp Basics and Idioms
2
Lisp Is Old
  • 1958 John McCarthy writes an algebraic list
    processing language for AI work
  • McCarthys grad student wrote an interpreter for
    it
  • Strongly tied to AI research during the 70s and
    80s
  • Fell from prominence during the AI Winter

3
Lisp Is New
  • Paul Grahams essays Beating the Averages,
    Lisp in Web-Based Applications
  • Eric Raymond "LISP is worth learning for the
    profound enlightenment experience you will have
    when you finally get it. That experience will
    make you a better programmer for the rest of your
    days, even if you never actually use LISP itself
    a lot.
  • Recent development of open source versions

4
Lisp is a Family of Languages
  • Common Lisp ANSI Standard written in the 80s
    caused languages to coalesce, then
    implementations to flourish
  • Scheme A conceptually cleaner variant with a
    smaller specification
  • Proprietary LispWorks, Allegro
  • Open Source SBCL, CLisp
  • Others compile to C, run on JVM, etc

5
Lisp is Functional, But Not Strictly
  • Functional is the most natural to write
  • Can make sequential blocks, either explicitly or
    in constructs
  • Can make and change values if needed
  • Can build and incorporate new paradigms as
    necessary, i.e. CLOS
  • Lisp is strongly typed, dynamic typed

6
Lisp Has Lots of Parentheses
  • "Lisp has all the visual appeal of oatmeal with
    fingernail clippings mixed in." -Larry Wall
  • Used to group expressions
  • Makes syntax simple and consistent
  • Most forms are (function args)

7
But the Parentheses Arent a Big Deal
  • "Parentheses? What parentheses? I haven't
    noticed any parentheses since my first month of
    Lisp programming. I like to ask people who
    complain about parentheses in Lisp if they are
    bothered by all the spaces between words in a
    newspaper" - Ken Tilton
  • Editors indent automatically
  • Emacs commands to balance and close parens
  • Paredit (Emacs library) lets you manipulate sexps
    directly

8
Lisp Uses Symbols
  • Like variables but better
  • Like pointers but less dangerous
  • Assign a name to a value
  • Values can be lots of things numbers, strings,
    functions, lists, other data structures

9
Lisp Has First Class Functions
  • Easy to define
  • (defun hello-world () (format t hello, world))
  • Can be passed as parameters
  • Can be returned as values from other functions
  • Anonymous functions too!

10
Lisp Has Flexible Parameters
  • Parameters can be optional, with defaults
  • (defun foo (a optional b) (list a b))
  • (defun foo2 (a optional (b 10)) (list a b))
  • Parameter lists can be variable length
  • (defun (rest numbers) )
  • Keyword parameters
  • (defun foo3 (key a b) )

11
Lisp Uses Pairs
  • Lists are chains of pairs
  • Can make other trees, etc as well

12
Lisp Uses Lists
  • "It is better to have 100 functions operate on
    one data structure than to have 10 functions
    operate on 10 data structures." - Alan J. Perlis
  • Tons of functions for manipulating lists
  • Useful for recursive definitions
  • Lists arent perfect so...

13
Lisp Has More Than Just Lists
  • Vectors fixed size sequences
  • Arrays can be multidimensional, resizable
  • Sequence functions on collections COUNT, FIND,
    POSITION, REMOVE, SUBSTITUTE, etc
  • This is one place where syntax would help
  • (aref a 5) instead of a5

14
Lisp Does Lots More
  • File and File I/O
  • Advanced object system using generic functions
    and message passing
  • Text formatting
  • Fancy iteration constructs
  • Conditions and restarts
  • Libraries for other things

15
Lisp Has Lots of Free Online Resources
  • Common Lisp First Contact
  • A Gentle Introduction to Symbolic Computation
  • Structure and Interpretation of Computer Programs
  • Practical Common Lisp
  • OnLisp
Write a Comment
User Comments (0)
About PowerShow.com