SICP exercise 1.01

From Drewiki

Jump to: navigation, search

Problem

What is the result printed by the interpreter in response to each expression given below, assuming the sequence of expressions is evaluated in the order in which it's shown?

Solution

10

Output:

10


(+ 5 3 4)

Output:

12


(- 9 1)

Output:

8


(/ 6 2)

Output:

3


(+ (* 2 4) (- 4 6))

Output:

6


(define a 3)

Output:



(define b (+ a 1))

Output:



(+ a b (* a b))

Output:

19


(= a b)

Output:

#f


(if (and (> b a) (< b (* a b)))
    b
    a)

Output:

4


(cond ((= a 4) 6)
      ((= b 4) (+ 6 7 a))
      (else 25))

Output:

16


(+ 2 (if (> b a) b a))

Output:

6


(* (cond ((> a b) a)
         ((< a b) b)
         (else -1))
   (+ a 1))

Output:

16
Personal tools