Highlights of chapter 2, Winston and Horn
Lisp procedures and data are symbolic expressions
1. (+ 3.14 2.71)
This is a list with 3 elements separated by spaces.
The procedure (or function) is always specified first, followed by the arguments (parameters).
3.14 and 2.71 are the parameters to the function ‘+’.
This is called prefix notation.
We’re using procedure and function synonymously.
A user defined procedure is supplied (defined) by the programmer.
A collection of procedures that work together is called a program.
An algorithm is a specification for how to do something.
An algorithm is a abstract specification that must be concrete enough to be recast as a procedure.
Numeric atoms (numbers): 27 and 3.14
Symbolic atoms (symbols): FOO B27, HYPHENATED-SYMBOL, FIRST, and +
Chapter summary
Lisp means symbol manipulation. Lisp stands for List Processing.
Lisp procedures and data are symbolic expressions.
FIRST and REST take lists apart. (also SECOND, THIRD, etc.)
CAR and CDR are older versions. (also CADR, CADDR, etc.)
Quoting stops evaluation.
SETF assigns values to symbols.
SETF accepts multiple symbol-value pairs.
Certain atoms evaluate to themselves. (T, NIL, and numbers)
CONS, APPEND, and LIST construct lists
CONS, APPEND, and LIST do not alter symbol values
NTHCDR, BUTLAST, and LAST shorten lists. Each of these returns a list.
LENGTH and REVERSE work on top-level elements.
ASSOC looks for indexed sublists.
(setf sarah ‘((height 0.54) (weight 4.4)))
(assoc ‘weight sarah) returns (WEIGHT 4.4)
Lisp offers integers, ratios, and floating point numbers
(/ 22 7) returns 22/7, (float (/ 22 7)) returns 3.14285…
A few primitives make up a basic repertoire: MAX, MIN, EXPT, SQRT, ABS