CS 538
2-16-2000

Inovations of Lisp (list processor)

  1. 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.
  2. Functional programming style - lets the programmer do lots of computations with few assignments.
  3. Naturally Recursive
  4. Dynamic typing - types can change as you go, as the program progresses.
  5. Dynamic data structures (including garbage collection)
  6. Functions are "first class" - for example you can pass functions as parameters or store them data structures
  7. Formal semantics - tell precisely what programs do
  8. Integrated programming environment - combines editors, interpreters and debuggers

Scheme - a recent dialect of Lisp. (Scheme as in plan or sequence of goals)

  1. Lexically (static) scoped - lisp used dynamic scoping which leave a program sensitive to the choice of local names within functions.
  2. True first class functions
  3. 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

    1. 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
    2. 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
    3. Character string "ABC"
      char #\c
      special characters #/space and #/newline
    4. 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.
    A
    B


    (1.2 . "XYZ") and example of intermixing types
    1.2
    XYZ


    ((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!