Problem Set 5

home work!

Programming Language BSL

Purpose This problem set (primarily) concerns the design of functions on self-referential data definitions.

You must follow the design recipe. The graders will look for data definitions, contracts, purpose statements, examples/tests, and properly organized function definitions. For the latter, you must design templates. You do not need to include the templates with your homework, however, unless we ask for them. If you do include them, comment them out.

You might also note that your graders are now being instructed to grade off for badly laid-out code; proceed accordingly. See The Style for pointers.

Finger Exercises HtDP/2e: 141, 149, 150, 166, 167, 168, 169, 171, 172, 173, 174, 175, 176; in preparation of the next exam, consider solving any of the extended exercises in section 13. (As usual, "finger exercises" will not be graded; they are just for you to practice on.)

Due: Tuesday, February 17 at 7pm

image

Problem 1

Develop the function check-pass-6-10?, which consumes a list of passwords (represented as strings) and produces a boolean indicating whether all are at least 6 characters but no more than 10 characters long.

Generalize the function to check-pass?, which consumes a list of passwords and a minimum and maximum length and produces a boolean indicating whether all passwords are within the allowed length span.

Problem 2

Recall the data definition for a Shape from Problem Set 4.

  1. Provide a data definition for List-of-Shape

  2. Provide a template for processing such lists.

  3. Design the function magenta-shapes, which changes the color of all of the Shapes in the list to magenta.

  4. Design the function draw-shapes, which consumes a List-of-Shape and adds images of them to an empty scene of 500 x 500. It may be useful to learn about empty-image in the Helpdesk.

  5. Design the function shape-member?, which consumes a List-of-Shape losh and a Shape s and determines whether s occurs in losh.

Problem 3

Develop the function cesarify which consumes a list of symbols and returns the same list but with every instance of ’pizza doubled. For example,

(cesarify (cons 'wurst (cons 'huevos (cons 'pizza (cons 'pants

empty)))))

would be expected to return:

(cons 'wurst (cons 'huevos (cons 'pizza (cons 'pizza (cons 'pants

empty)))))

Problem 4

The goal of this problem is to develop a camera-roll program such as you may have on your smart phone. The camera-roll starts with the first photo and displays the next photo if the right arrow is pressed.

Here are the data definitions you should use:

;; LoImg (List-of-Image) is one of:

;; -- empty

;; -- (cons Image LoImg)

 

(define-struct cr (index images))

;; A CR (Camera Roll) is a (make-cr PositiveNumber LoImg)

;; intepretation:

;;  The index represents the position of the current image.

;;  The index must be between 0 and the number of images in LoImg.

Create a world program to display images from a CR and allow the user to scroll through the photos back and forth using the left and right arrow keys:

Design the function display-photo, which consumes a CR and returns the current image.

Design the function change-photo, which allows a user to change the current photo with the left and right arrow keys. If the current photo is the first photo, then pressing the left arrow should not change the photo. Likewise, if the current photo is the last photo, pressing the right arrow should have no effect.

Note: You will need to use several helper functions.