6.7
Week 9 Set b
Programming Language ISL
Due Date Wed at 9pm (Week 9)
Purpose To practice the design of functions on multi-recursive data definitions
Finger Exercises
Graded Exercises
Exercise 2 Your friends and you decided to create a maze exploration software. In the spirit of iterative refinement, you have decided to start with a simple model of mazes. In this simplest form, rooms in the maze always contain a single object and have always four exits, though some of them might be blocked. Here is one way to represent this choice as data:
(define-struct room (object north east south west)) ; A Room is a structure: ; (make-room Symbol Exit Exit Exit Exit) ; An Exit is [Maybe Room], meaning it is one of: ; – #false ; – Room ; interpretation (make-room 'ax r1 r2 r3 r4) describes a room ; in a maze. The room contains an 'ax. Its Exits lead to four other ; rooms: r1, ..., r4, through the door to the north, east, south, ; west, respectively. If an Exit is #false, the door is locked. To find out whether this representation can be easily processed, you have decided to design the function all-objects, which consumes a Room and produces the list of all objects it can find by traversing the entire maze.
Suggestion You may wish to use check-satisfied to formulate tests. See HtDP/2e for examples or consider this one:
; Number -> [Number -> Boolean] ; produce a function that checks whether some number is ; between 0 (inclusive) and n (exclusive) (define (between-0-and n) (local (; Number -> Boolean ; is x between 0 (inclusive) and n (exclusive) (define (between x) (and (<= 0 x) (< x n)))) between)) (check-satisfied (random 10) (between-0-and 10))