2011-08-30

SICP Exercise 1.2: From Infix to Prefix

Translate the following expression into prefix form

Oh the joys of producing equations in MS Word... Anyway, I translate this as:
(/ (+ 5
      4
      (- 2
         (- 3
            (+ 6
               (/ 4 5)))))
   (* 3
      (- 6 2)
      (- 2 7)))
The result of interpreting this is interesting:
Rather than converting the integer values to decimal fractions (or, more likely, floating point numbers), Scheme represents the result as a rational number.

No comments:

Post a Comment