;; For review: (define-struct city (name nhbrs seen?)) ;; ;; A city is a ;; (make-city [symbol] [list-of-cities] [boolean]) ;; where seen? is to be used later, in path-finding. ; Initially no neighbors: (define nyc (make-city 'nyc empty false)) (define la (make-city 'la empty false)) (define slc (make-city 'slc empty false)) (define hou (make-city 'houston empty false)) (define nome (make-city 'nome empty false)) (define reno (make-city 'reno empty false)) (define cities (list nyc la slc hou nome reno)) (set-city-nhbrs! nyc (list la slc hou nyc)) (set-city-nhbrs! la (list reno slc nyc)) (set-city-nhbrs! hou (list nyc la)) (set-city-nhbrs! slc (list reno)) (set-city-nhbrs! reno (list slc)) ;; map-append: (alpha --> list-of-beta), list-of-alpha --> list-of-beta ;; Map f to each element of inputs, ;; where f returns a list each time. ;; Return the appended results. ;; (define (map-append f inputs) (foldr (lambda (frst rr) (append (f frst) rr)) empty inputs)) ; An alternate implementation, if you know "apply": ; (apply append (map f inputs)) ;; contains?: list-of-any, any --> boolean ;; Is target in data? ;; Uses eq? for comparison. ;; (define (contains? target data) (ormap (lambda (datum) (eq? datum target)) data)) ; ; Kinda like: (apply or (map .. data)) ;; one-away-from: list-of-city --> list-of-city ;; (define (one-away-from srcs) ...) ;; keep-looking: list-of-city, city --> list-of-city ;; Repeatedly call keep-looking until dest is in srcs. ;; (define (keep-looking srcs dest) (cond [.. ..] ; Base-case [.. ..] ; inductive case: keep-looking one-away-from srcs.