1.1

A function is defined with paramters , and passed arguements when used

;; Applicative Order ("evaluate the arguments first)
(square (+ 1 5))
(square 6)
(* 6 6)
;; Normal Order (“fully expand and then reduce")
(square (+ 1 5))
(* (+ 1 5) (+ 1 5))
(* 6 6)

TAKE NOTE!: Do not try to replace Scheme's if statement with a function. The default if statement is a special form which means that even when an interpreter follows applicative substitution, it only evaluates one of its parameters- not both.

;;block strcuture = nesting of definitions

;;lexical scoping = x is accessible from procedures in sqrt even though not in argument

(define (sqrt x)
  (define (good-enough? guess)
    (< (abs (- (square guess) x)) 0.001))
  (define (improve guess)
    (average guess (/ x guess)))
  (define (sqrt-iter guess)
    (if (good-enough? guess)
        guess
        (sqrt-iter (improve guess))))
  (sqrt-iter 1.0))
alt text

We use procedural abstraction which suppresses implementation details by treating procedures as black boxes .

Last updated