add ch1 ex4
This commit is contained in:
parent
0b389277e4
commit
7c71ce41da
1 changed files with 21 additions and 0 deletions
21
chapter_1/ex_4.rkt
Normal file
21
chapter_1/ex_4.rkt
Normal file
|
@ -0,0 +1,21 @@
|
|||
#lang sicp
|
||||
|
||||
;Observe that our model of evaluation allows for combinations whose operators are compound expressions. Use this observation to describe the behavior of the following procedure:
|
||||
;(define (a-plus-abs-b a b) ((if (> b 0) + -) a b))
|
||||
|
||||
(define (a-plus-abs-b a b)
|
||||
((if (> b 0) + -) a b)
|
||||
)
|
||||
|
||||
(a-plus-abs-b -6 3) ;--> the result is -3
|
||||
(a-plus-abs-b 3 -3) ;--> the result is 6
|
||||
(a-plus-abs-b -3 -3) ;--> the result is 0
|
||||
(a-plus-abs-b -3 3) ;--> the result is 0
|
||||
(a-plus-abs-b -3 0) ;--> the result is -3
|
||||
|
||||
;This tells us that if b is positive, we use + procedure. If not them use - procedure
|
||||
;from (a-plus-abs-b -6 3) --> the result shows -3 --> -6 + (3) = -3 // because b = (3) we use + procedure
|
||||
;from (a-plus-abs-b 3 -3) --> the result shows 3 --> 3 - (-3) = 6 // because b = (-3) we use - procedure
|
||||
;from (a-plus-abs-b -3 -3) --> the result shows 0 --> -3 - (-3) = 0
|
||||
;from (a-plus-abs-b -3 3) --> the result shows 0 --> -3 + (3) = 0
|
||||
;from (a-plus-abs-b -3 0) --> the result shows -3 --> -3 + (0) = -3
|
Loading…
Add table
Reference in a new issue