John McCarthy shows that given a few operators and notation for functions, you can build a whole programming language.
Lisp Model of Computation
expression:
- an
atom, which is a sequence of letters (e.g., foo) - a list of zero or more expressions, separated by whitespace and enclosed by parenthesis.
Seven primitive operators:
(quote x)returns x. For example,'x,(quote a),(quote (a b c))- by quoting a list, we prevent it from being evaluated
(atom x)returns the atomstif the value of x is an atom or the empty list.(atom 'x) -> t(atom '(a b c)) -> ()(atom '())-> t
(eq x y)returnstif the values ofxandyare the same atom or both the empty list(eq 'a 'a) -> t(eq 'a 'b)-> ()
(car x)returnsx’s first element(cdr x)returns everything after the first element(cons x y)returns a list containing the valuexfollowed by the elements of the value ofy(cond (p1 e1) …(pn en). Thepexpressions are evaluated in order until one returnst. When one is found, the correspondingeexpression is returned as the value of the wholecondexpression.
Denoting function
(lambda (p1...pn) e).p1, ...pnare atoms(parameters) andeis an expression- function call:
((lambda (p1...pn) e) a1...an)- Each expression
aiis evaluated. Theneis evaluated. During the evaluation ofe, the value of any occurrence of one of thepiis the correspondingaiin the most recent function call - parameters can be used as operators in expressions as well as arguments.
- Each expression
((lambda (f) (f '(b c))) '(lambda (x) (cons 'a x)))
output:(a b c)
(label f (lambda (p1...pn) e))denotes a function behaves like(lambda (p1...pn) e)(defun null. (x) (eq x ‘()))(defun and. (x y) (cond (x (cond ( y ‘t) (‘t ‘()))) (‘t ‘())))
Using just quote, atom, eq, car, cdr, cons , cond, we can define a function eval, that actually implements our language, and then using that we can define any additional functions we want. This is a very elegant model of computation.