CS 538
2-16-2000
Inovations of Lisp (list processor)
- Symbolic computation - allows manipulation of symbols rather than just numbers, for use in algebraic
equations, differential equations and other fields of math and artificial intelligence.
- Functional programming style - lets the programmer do lots of computations with few assignments.
- Naturally Recursive
- Dynamic typing - types can change as you go, as the program progresses.
- Dynamic data structures (including garbage collection)
- Functions are "first class" - for example you can pass functions as parameters or store them data
structures
- Formal semantics - tell precisely what programs do
- Integrated programming environment - combines editors, interpreters and debuggers
Scheme - a recent dialect of Lisp. (Scheme as in plan or sequence of goals)
- Lexically (static) scoped - lisp used dynamic scoping which leave a program sensitive to the choice of local names within functions.
- True first class functions
- Access to control flow via continuations - allows one in a sense to go back in time. At any
point in execution one can store the execution context of that instant. Anytime later you can then go back to that
moment, change the context and continue on with your execution from there.
Data structs are dynamic which allows things like integers of unlimitted precision
ex. (* 1 2 3) gives us 1*2*3 = 6
but we can also do this with extended length integers for example
(* 100000000000 1000000000000000000) will also work giving us 100000000000000000000000000000
Scheme also automatically changes types
Atomic Data
- Symbols - any run of extended character set except prefix of number - ie it can't start with a number
for example ABC
Hi-mom
+ overloading of defined operators is allowed
<=! define your own
- Numeric values
Integers - to any precision 123
Real (float) - sometimes extended sometimes dependent upon hardware
Rational - (/ 1 3) = 1/3 instead of .3333333333
Complex - (sqrt -1) = 0 + 1i
- Character string "ABC"
char #\c
special characters #/space and #/newline
- Booleans
#t for true
#f for false
Binary Trees - (S-exprs) "Dotted pairs"
examples:
(A . B) where A and B are the left and right subtrees respectively. Binary trees are often represented as below.
(1.2 . "XYZ") and example of intermixing types
((A . B) . C) nested binary trees
Functions that build and access S-exprs
cons = construct
(cons 1 2) = (1 . 2)
Access is via:
car = left = head of list
cdr = right = rest of list or the tail
(car(cons 1 2)) = 1
(cdr(cons 1 2 )) = 2
Lists
zero elements ()
one element (1) to build a one element list (cons 1 '()) = (1)
two elements (1 2) (cons 2(cons 1 '()) = (2 1)
programs and data look similar - use ' character to tell them apart
'(1 2 3) is a data list the single quote at the beginning tells the compiler that it is data otherwise it would
try to evaluate the first element 1 as a function.
examples:
(car(cons(1 2)) = 1
(cdr '(1 2 3)) = (2 3)
car(cdr '(1 2 3)) = 2
cdr(cdr(cdr '(1 2 3))) = ()
cdr(cdr(cdr(cdr '(1 2 3)))) gives you a runtime error!