Text
The Root of Lisp
Paul Graham
Presenter: Ofa
Date: 2015.3.12
Agenda
John McCarthy
Operators
Function
Surprise
John McCarthy
Operators + notation for
functions = whole
programming language
C model vs Lisp model
The Euclid for
programming!!!
Operators
Expression = an atom or a list of
zero or more expressions
Atom: foo
List: (), ,(foo bar), (a b (c) d)
Value:
ex. 1+1=2; 1+1=>e, 2=>v, said
e returns v
If an e is a list, it can be the form:
(operator arguments*)
( ( 1 + 2 ) * 3)
( * ( + 1 2 ) 3 )
Symbolic
expression
List Atom
Number Symbol
Operators
(quote x) returns x
> ‘x
x
(atom x) returns the atom t if the
value of x is an atom or the empty
list, otherwise it returns () (falsity)
> (atom ‘a)
t
> (atom ‘(a b c))
()
Most distinctive feature of Lisp:
Code and data are made out of the same
data structures︎ and the quote operator is
the way we distinguish between them︎
Operators
(eq x y) returns t if x and y are the
same atom or both the empty list,
() otherwise
> (eq ‘x ‘x)
t
(car x) expects the value of x to
be a list, and returns the first
element of x
> (car ‘(a b c) )
a
(cdr x) expects the value of x be
a list, and returns everything after
the first element
> (cdr ‘(a b c) )
(b c)
(cons x y) expects the value of y
to be a list, and returns a list
containing the value of x followed
by the elements of the value of y
> (cons ‘a ‘(b c))
(a b c)
> (cdr (cons ‘a ‘(b c))
(b c)
Operators
(cond (p1 e1)…(pn en) ) the p
expressions are evaluated in order
until one returns t; when one is
found, the value of the
corresponding e expression is
returned
> (cond ( ( eq ‘a ‘b) ‘first) ( (
atom ‘a) ‘second) )
second
the same as {key, value} in C styled
Function
Function call
( ( lambda (p1…pn) e) a1…an)
p1 <- e(a1), a1 is evaluated and then e, p1
becomes the corresponding value of a1
> ( ( lambda (x y) (cons( x (cdr y) ) ) ‘z ‘(a b c) )
(z b c)
Surprise
A function that turns out to be an interpreter of a
language?!
-> We can define a function that takes as an
argument any Lisp expression, and returns its value
ref page 8 to see the details
Summary
Recursion
A new concept of variables
Garbage-collection
Programs composed of
expressions
The whole language always
available
Python!!!

2015.3.12 the root of lisp

  • 1.
    Text The Root ofLisp Paul Graham Presenter: Ofa Date: 2015.3.12
  • 2.
  • 3.
    John McCarthy Operators +notation for functions = whole programming language C model vs Lisp model The Euclid for programming!!!
  • 4.
    Operators Expression = anatom or a list of zero or more expressions Atom: foo List: (), ,(foo bar), (a b (c) d) Value: ex. 1+1=2; 1+1=>e, 2=>v, said e returns v If an e is a list, it can be the form: (operator arguments*) ( ( 1 + 2 ) * 3) ( * ( + 1 2 ) 3 ) Symbolic expression List Atom Number Symbol
  • 5.
    Operators (quote x) returnsx > ‘x x (atom x) returns the atom t if the value of x is an atom or the empty list, otherwise it returns () (falsity) > (atom ‘a) t > (atom ‘(a b c)) () Most distinctive feature of Lisp: Code and data are made out of the same data structures︎ and the quote operator is the way we distinguish between them︎
  • 6.
    Operators (eq x y)returns t if x and y are the same atom or both the empty list, () otherwise > (eq ‘x ‘x) t (car x) expects the value of x to be a list, and returns the first element of x > (car ‘(a b c) ) a (cdr x) expects the value of x be a list, and returns everything after the first element > (cdr ‘(a b c) ) (b c) (cons x y) expects the value of y to be a list, and returns a list containing the value of x followed by the elements of the value of y > (cons ‘a ‘(b c)) (a b c) > (cdr (cons ‘a ‘(b c)) (b c)
  • 7.
    Operators (cond (p1 e1)…(pnen) ) the p expressions are evaluated in order until one returns t; when one is found, the value of the corresponding e expression is returned > (cond ( ( eq ‘a ‘b) ‘first) ( ( atom ‘a) ‘second) ) second the same as {key, value} in C styled
  • 8.
    Function Function call ( (lambda (p1…pn) e) a1…an) p1 <- e(a1), a1 is evaluated and then e, p1 becomes the corresponding value of a1 > ( ( lambda (x y) (cons( x (cdr y) ) ) ‘z ‘(a b c) ) (z b c)
  • 9.
    Surprise A function thatturns out to be an interpreter of a language?! -> We can define a function that takes as an argument any Lisp expression, and returns its value ref page 8 to see the details
  • 10.
    Summary Recursion A new conceptof variables Garbage-collection Programs composed of expressions The whole language always available Python!!!