Note: this wiki is now retired and will no longer be updated!

The static final versions of the pages are left as a convenience for readers. Note that meta-pages such as "discussion," "history," etc., will not work.

SICP exercise 1.04

From Drewiki
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