sicp.htm
Structure and Interpretation of Computer Programs
Every language has:
- Primitive expressions
- Means of combination
- Means of abstraction
E.g.,
- 136 214)
(
2)
(define size 10) (define radius
To evaluate combinations we:
- Evaluate the sub-expressions
- Apply the procedure that is the value of the leftmost subexpression to the other arguments
This is recursive in nature.
2 (* 4 6))
(* (+ 3 5 7)) (+
Compound procedures:
- Numbers and arithmetic are primitive data and procedures
- Nesting combinations provides a means of combining operations
- Definitions that associate names with values provide a limited means of abstraction
* x x))
(define (square x)(
21)
(square 441
There are two ways of evaluating:
- Applicative order: evaluate the arguments and then apply
- Normal order: fully expand and then reduce
Lisp uses applicative-order evaluation.
Conditionals
(define (abs x)0) x)
(cond ((> x 0) 0)
((= x 0) (- x))))
((< x
(define (abs x)0) (- x))
(cond ((< x (else x)))