Exercise 1.4

Describe the behavior of the following procedure:

(define (a-plus-abs-b a b)
  ((if (> b 0) + -) a b))

Note that the if procedure will itself return a procedure: either + or -. So, if b is greater than 0, the procedure evaluated will be:

(+ a b)

resulting in a positive number, whereas if b is less than 0 (i.e. negative), the procedure evaluated will be:

(- a b)

also resulting in a positive number.

Back to exercises