6.7

Assignment 7

home work!

Programming Language BSL

Due Date Thurs 2/2 at 11:59pm

Possible Points 35

Purpose To begin working with self-referntial data.

Graded Exercises
(define-struct layer [feeling more])
; An Ogre is one of:
; - "center"
; - (make-layer String Ogre)
; and represents the feelings an ogre has

Exercise 1 Design a function that given an Ogre outputs how many layers it has.

Exercise 2 Design a function that given an Ogre outputs its feelings. The following tests should pass:
(check-expect (feelings "center") "Ogre is feeling:")
(check-expect
 (feelings (make-layer "sad" (make-layer "happy" (make-layer "contemplative" "center"))))
 "Ogre is feeling: sad happy contemplative")

; A Nat is one of:
; - 0
; - (add1 Nat)

Exercise 3 Design a function that given a natural number n and a feeling of an Ogre outputs an Ogre that feels that feeling n times.

(define-struct canvas [width height])
(define-struct painting [image loc beneath])
; A Painting is one of:
; - (make-canvas Number Number)
;   which represents an empty canvas of a certain width/height
; - (make-painting Image Posn Painting)
;   which represents the top layer of a painting with an image at a position

Exercise 4 Design a function that draws a painting.