Professional Documents
Culture Documents
;; Consider this to be a primitive function that comes with the data definitions
;; and that given a room name it produces the corresponding room. Because
;; this consumes a string and generates a room calling it will amount to a
;; generative step in a recursion through a graph of rooms.
;; You should not edit this function, but you can experiment with it to see how
;; it works.
;;(@htdf lookup-room)
;;(@signature String -> Room)
(define (lookup-room name)
(local [(define (scan lst)
(cond [(empty? lst) (error "No room named " name)]
[else
(if (string=? (room-name (first lst)) name)
(first lst)
(scan (rest lst)))]))]
(scan ROOMS)))
#;
(define (fn-for-house r0)
;; path is (listof String); context preserving accumulator, names of rooms
(local [(define (fn-for-room r path)
(if (member (room-name r) path)
(... path)
(fn-for-lor (room-exits r)
(cons (room-name r) path))))
(define (fn-for-lor lor path)
(cond [(empty? lor) (...)]
[else
(... (fn-for-room (lookup-room (first lor)) path)
(fn-for-lor (rest lor) path))]))]
(fn-for-room r0 empty)))