From 7c71ce41dad0230c0461c7d2444c20fe771a5c99 Mon Sep 17 00:00:00 2001 From: Juthatip McDevitt Date: Sun, 27 Jul 2025 10:38:18 -0500 Subject: [PATCH] add ch1 ex4 --- chapter_1/ex_4.rkt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 chapter_1/ex_4.rkt diff --git a/chapter_1/ex_4.rkt b/chapter_1/ex_4.rkt new file mode 100644 index 0000000..0d28050 --- /dev/null +++ b/chapter_1/ex_4.rkt @@ -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