Музыка: |
structure and interpretation of computer programs |
Entry tags: | sicp |
1.2 1.3 1.5
#| the output is from MIT's Scheme compiler |#
; 1.2
1 ]=> (/ (+ 5 4
(- 2
(- 3
(+ 6 (/ 4 5)))))
(* 3
(- 6 3)
(- 3 7)))
;Value: -37/90
1 ]=>
; 1.3
1 ]=> (define (sum-of-squares a b) (+ (* a a) (* b b)))
;Value: sum-of-squares
1 ]=> (define (sum-of-larger-nums a b c) (cond ( (and (<= a b) (<= a c)) (sum-of-squares b c)) ( (and (<= a b) (>= a c)) (sum-of-squares a b)) ( (and (<= a c) (>= a b)) (sum-of-squares a c)) (else (if (< b c) (sum-of-squares a c) (sum-of-squares a b)))))
;Value: sum-of-larger-nums
1 ]=>
; 1.5
#|
normal-order evaluation will postpone evaluating the value of (p) until the first condition of if-clause fails. Since x==0, (p) will never be evaluated, and the value of 0 will be returned by the invocation of test.
applicative-order evaluation will first evaluate argument values. Therefore it will trip on (p), which is undefined (???). In other words, it will never reach the stage of performing test on the operands
|#