Mente

sicp.htm

Structure and Interpretation of Computer Programs

Every language has:

E.g.,

(- 136 214)

(define size 2)
(define radius 10)

To evaluate combinations we:

  1. Evaluate the sub-expressions
  2. 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:

(define (square x)(* x x))

(square 21)
441

There are two ways of evaluating:

Lisp uses applicative-order evaluation.

Conditionals

(define (abs x)
  (cond ((> x 0) x)
        ((= x 00)
        ((< x 0) (- x))))

(define (abs x)
  (cond ((< x 0) (- x))
        (else x)))