click to add subtle - mitweb.mit.edu/rlm/public/lisp/lisp.pdf · lisp is a family of languages....

23
A Tale of Two Lisps Click to add subtle

Upload: others

Post on 06-Sep-2019

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

A Tale of Two LispsClick to add subtle

Page 2: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

LISP is a family of languages.

Though each member of this family has its own quirks, they all share the common attributes of LISP:

● Interactive (REPL)● Polish Notation (S-expressions)● LISP Programs are Lists (homoiconic)

20 minute crash course in LISP

Page 3: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Core Concepts of Lisp

Real Metaprogrammingperl "macros"C macros

Code as datarun-time programming

S-expressionsMacros

backquote comma syntax

Page 4: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

What you expect out of Lisp

Garbage collectionMulti-paradigm programming

functionalimperativeobject-oriented

Dynamic typingHomoiconicityLists

OMG lists

Page 5: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Examples

● Syntax● Functions● Macros

Page 6: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Syntax

LISP syntax is very regular.

A LISP program is just a sequence of lists.

Because of this, LISP code can be manipulated by LISP (which is the List processing language after all)

Page 7: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Functions

Value slot vs Function slotWhat sorts of things can be functions?

Things that have been defun'dLambda expressionsSymbols

Using funcallWays you should never bind a function

Page 8: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Macros

Code is data.QuotingEval exampleHow macros work

a simple macro examplea more complex macro example

It is possible to write code at runtime

Page 9: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Two Theories of Computation

● Turing Machine

State Machine +Tape

● Lambda Calculus

Combinations of Functions

Page 10: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Equal but Different

Turing Machines → procedural, imperative style.

Assembly, ALGOL, FORTRAN, C, etc

Lambda Calculus → compose functions.

Haskell, LISP

Page 11: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Timeline

1956: lisp is conceived1958: first implementation (IBM 704)1962-1970ish: Maclisp

On the PDP-10 and other machines1981: Zetalisp (Lisp Machine Lisp)1984: Common Lisp the Language1985: *LISP / Emacs LISP1994: ANSI Common Lisp2007: Clojure 1.0

Page 12: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Early LISP (1960)

Invented by John McCarthy here at MIT.First Implemented by Steve Russel on an IBM 704 computer.

Page 13: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

LISP 1

M-Expressions --> S-expressions

Page 14: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

LISP 1

The first interpreter for LISP on the IBM 704 had:● Garbage Collection (“reclamation cycle”)● Recursive Functions/Stack (“public push-

down list”)● No M-Expressions (they didn't have time to

implement them!)● No Macros● REPL !! (Flexowriter)

Page 15: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Maclisp

setfbit vectorsarraysstringsfloats and bignumsno lexical scopingloop macrofewer equality forms than CLflexible read base

Page 16: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Zetalisp

everything in maclispcomplex numbersrationalslexical scopingdynamic closuresobject system (flavors)base 8 (default)

Page 17: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Zetalisp Demo

Dynamic closuresLists as functions

Page 18: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Common Lisp

Significant influence from ZetalispCLOS (common lisp object system)

- multiple inheritanceLanguage is static: old libraries still work

Page 19: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

*LISP (Connection Machine)

Common Lisp, with macros which enabled use of parallel variables

Page 20: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

EMACS LISP

Mostly used for scripting new functions for editing files with EMACS.

Dynamically Scoped --- interferes with closures.

Page 21: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Clojure

Released by Rich Hickey in 2007.

Integrates with Java and the JVM

Advanced support for parallel, thread-safe code.

Immutable data structures.

Page 22: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Lisp Trivia

LISP is second oldest language in modern use.

Used in AutoCAD, Emacs, Reddit, GIMP, Crash Bandicoot, Toy Story.

Gollum from Lord of the Rings was animated on a Symbolics Lisp Machine.

Page 23: Click to add subtle - MITweb.mit.edu/rlm/Public/lisp/lisp.pdf · LISP is a family of languages. Though each member of this family has its own quirks, they all share the common attributes

Trivial Trivia

The computer from Jurassic Park was a Connection Machine Model CM-5.