8.12

Lecture 13: More self-reference🔗

This assignment is due on Sunday, February 18 at 11:59pm. Submit it using Handin as assignment lecture13.

; A Doll is one of:
; - (make-small-doll String)
; - (make-larger-doll Doll)
(define-struct small-doll (color))
(define-struct larger-doll (smaller))

Exercise 1. Design the function green-doll which takes a Doll and returns a similar Doll, but the small Doll at the center has the color "green". Here’s an example:
(check-expect (green-doll (make-larger-doll
                           (make-small-doll "red")))
              (make-larger-doll
               (make-small-doll "green")))

Exercise 2. Recall from Who can name the bigger number? by Aaronson that “5 tetrated to the 3” means 5 raised to its own power 3 times. That is (expt 5 (expt 5 5)) = (expt 5 (expt 5 (expt 5 1))), a number with 2185 digits. Design a function tetrated-5 that takes a NaturalNumber and returns 5 tetrated to it. Use the data definition of NaturalNumber at the end of the video above.