6.6

Assignment 7

home work!

Programming Language BSL

Due Date Thursday 10/04 at 9pm

Purpose To design functions over unions and self-referential data.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • All steps of the design recipe are required unless otherwise specified.

(define-struct circl [radius mode c])
(define-struct squar [side-length mode c])
(define-struct rectangl [width height mode c])
 
; A Shape is one of:
; - (make-circl Number Mode String)
; - (make-squar Number Mode String)
; - (make-rectangl Number Number Mode String)
; 
; Interpretation: One of multiple shapes
; - make-circl
;   - radius is the radius in pixels
;   - mode is the drawing mode
;   - c is the color to draw the circle
; - make-squar
;   - side-length is the side length in pixels
;   - mode is the drawing mode
;   - c is the color to draw the square
; - make-rectangl
;   - width is the width in pixels
;   - height is the height in pixels
;   - mode is the drawing mode
;   - c is the color to draw the square
 
; A Mode is one of:
; - "solid"
; - "outline"
; Interpretation: The drawing mode for a shape (either filled or outline)

Exercise 1 Provide examples and templates for the above data definitions for Shape and Mode.

Exercise 2 Describe in a comment the difference between circle and circl.

Exercise 3 Design a function which accepts a Shape and returns an Image of that shape.

Exercise 4 Design a function which flips the Mode of a Shape.

(define-struct monkey [name c others])
 
; A MonkeyChain is one of:
; - "barrel"
; - (make-monkey String String MonkeyChain)
; 
; Interpretation: A collection of monkeys
; - "barrel" is an empty barrel
; - make-monkey
;   - name is the name of this monkey
;   - c is the color of this monkey
;   - others is the other monkeys (or barrel) it is attached to

Exercise 5 Provide examples and a template for MonkeyChain.

Exercise 6 Design a function that counts how many "purple" monkeys there are in a MonkeyChain.

Exercise 7 Design a function that accepts a MonkeyChain and a String representing a name; it should determine whether or not a monkey with the given name exists in the MonkeyChain.

Exercise 8 Design a function that accepts a MonkeyChain and produces an image of the colored names of the monkeys above each other. Monkeys at the front of the monkey chain should appear above the others. A barrel can be drawn with an empty-image. Above all of them (no matter how many monkeys there are), the text "The monkey names are:" should appear in "violet".

Exercise 9 Design a data definition for a list of Booleans. Be sure to use cons and '(). No interpretation is needed as this list of booleans has no specific context, but be sure to include the rest of the steps of the design recipe for data.

Exercise 10 Design a function which determines if any element in a list of booleans is #true. Do not use member or member?.

Exercise 11 Design a function which negates every element in a list of booleans. In other words, it converts every #false to #true and vice versa.