SICP exercise 1.04

From Drewiki

(Redirected from SICP exercise 1.4)
Jump to: navigation, search

Problem

Describe the behavior of the following procedure:

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

Solution

The if expression checks whether the value of the procedure argument b is positive. If it is, the if expression evaluates to the primitive +, otherwise it evaluates to the primitive -. This primitive is then applied to its arguments, the values of the procedure arguments a and b.

Personal tools