SICP - Solution: Exercise 1.4

Sep 26, 2018 21:03 · 62 words · 1 minute read

Exercise 1.4

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))

Solution

If $b$ is strictly a positive number, the function returns $a+b$, else it returns $a-b$.

In other words, this function compute ${a+\left|b\right|.}$