Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
4 ;A word is either
5 ;1. empty or
6 ;2. (cons s w)
7 ;where s is a one-letter symbol ('a, 'b, ...) and '_, and w is a word.
8 ;
9 ;reveal-list : word word symbol -> word
10 ;Given chosen (word), status (word), and guess (one-letter symbol), return the new status word. A status word represents the progress of the hangman game. If guess matches a letter in chosen, replace '_ in status with the letter. Otherwise, return the same status word.
11 ;ASSUMPTION: both chosen and status are the same length.
13 ;Examples
14 ;(reveal-list '(b r e a d) '(b r e _ _) 'a)
15 ;'(b r e a _)
16 ;
17 ;(reveal-list '(b r e a d) '(b r e _ _) 'x)
18 ;'(b r e _ _)
19 ;
20 ;(reveal-list '(m o o n) '(_ _ _ n) 'o)
21 ;'(_ o o n)
23 (define (reveal-list chosen status guess)
24 (cond
25 [(empty? chosen) empty]
26 [(cons? chosen)
27 (cond
28 [(symbol=? guess (first chosen))
29 (cons (first chosen) (reveal-list (rest chosen) (rest status) guess))]
30 [else (cons (first status) (reveal-list (rest chosen) (rest status) guess))])]))