Skip to content

Latest commit

 

History

History
40 lines (25 loc) · 1.06 KB

Chapter3.md

File metadata and controls

40 lines (25 loc) · 1.06 KB

Chapter 3 Exercises

Exercise 1

Define a function called at-least-two? that takes one Nat argument and evaluates to an Atom. at-least-two? evaluates to 't if the Nat is greater than or equal to 2 otherwise it evaluates to 'nil.

Note: The only Nat eliminator you should need in the body of at-least-two? is which-Nat.

Answer

Exercise 2

Rewrite the definition of + (in frame 3.27) using the rec-Nat eliminator instead of the iter-Nat eliminator.

 (define step-+
   (lambda (sum-n-1)
     (add1 sum-n-1)))

 (define +
   (lambda (n j)
     (iter-Nat n
       j
       step-+)))

Answer

Exercise 3

Define a function called exp that takes two Nat arguments and evaluates to a Nat. exp evaluates to the exponentiation, a^b, of the two passed arguments.

Answer

Exercise 4

Define a function called max that takes two Nat arguments and evaluates to a Nat. max evaluates to the larger of the two passed arguments.

Answer