LISP (LISt Processing Language)
Prefix notation
(function argument1 argument2 ...)
(element1 element2 ...)
(some lisp code) ; this is a comment
Functional language
Some on-line information (URLs):
lots of pointers to information
http://www.apl.jhu.edu/~hall/lisp.html
LISP primer
http://http.tamu.edu:8000/~colin/lp/lp.html
Its the language with all the parenthesis
embedded lists
(+ (* 8 5) (* 2 10) (- 100 (* 2 10)) (+ 10 5))
Symbols, Atoms, and Lists
quote, append, list, first, rest, second, third, fourth,
length, last, cons, car, cdr, cadr, caddr, ...
Special forms
does not follow normal functional syntax
constant data: (quote hello) also `hello
variables: (setf x 20)
conditionals:
(if (> x y) (- x y) (- y x))
reference to a function:
(function +) also #'+
defining functions:
(defun abs-value (x y)
"computes the absolute value"
(if (> x y) (- x y) (- y x)))
Applying functions
apply:
(apply #'+ `(1 2 3 4))
funcall:
(funcall #'+ 1 2 3 4)
mapcar:
(mapcar #'abs-value `(10 20 30 40) `(40 30 20 10))
Unnamed functions
(lambda (parameters ...) body ...)
(lambda (x y) (if (> x y) (- x y) (- y x)))
Other types and functions
comparisons:
equal
=
determining types:
(listp x)
(atomp x)
strings:
"hello world"
(length "hello world") -> 11
(length "") -> 0
Recursion
(defun factorial (x)
(if (= x 1) 1 (* x (factorial (- x 1)))))
WHAT MAKES LISP DIFFERENT?
Built-in support for lists
Automatic storage management
Dynamic typing
First-class functions
Uniform syntax
Interactive environment
Extensibility
History