about summary refs log tree commit diff stats
path: root/arc/.traces/scheduler-deadlock2
diff options
context:
space:
mode:
Diffstat (limited to 'arc/.traces/scheduler-deadlock2')
0 files changed, 0 insertions, 0 deletions
23' href='#n23'>23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

































































                                                                                  
(define (animal node)
  (define (type node) (car node))
  (define (question node) (cadr node))
  (define (yespart node) (caddr node))
  (define (nopart node) (cadddr node))
  (define (answer node) (cadr node))
  (define (leaf? node) (eq? (type node) 'leaf))
  (define (branch? node) (eq? (type node) 'branch))
  (define (set-yes! node x)
    (set-car! (cddr node) x))
  (define (set-no! node x)
    (set-car! (cdddr node) x))

  (define (yorn)
    (let ((yn (read)))
      (cond ((eq? yn 'yes) #t)
	    ((eq? yn 'no) #f)
	    (else (display "Please type YES or NO")
		  (yorn)))))

  (display (question node))
  (display " ")
  (let ((yn (yorn)) (correct #f) (newquest #f))
    (let ((next (if yn (yespart node) (nopart node))))
      (cond ((branch? next) (animal next))
	    (else (display "Is it a ")
		  (display (answer next))
		  (display "? ")
		  (cond ((yorn) "I win!")
			(else (newline)
			      (display "I give up, what is it? ")
			      (set! correct (read))
			      (newline)
 			      (display "Please tell me a question whose answer ")
			      (display "is YES for a ")
			      (display correct)
			      (newline)
			      (display "and NO for a ")
			      (display (answer next))
			      (display ".")
			      (newline)
			      (display "Enclose the question in quotation marks.")
			      (newline)
			      (set! newquest (read))
			      (if yn
				  (set-yes! node (make-branch newquest
							   (make-leaf correct)
							   next))
				  (set-no! node (make-branch newquest
							  (make-leaf correct)
							  next)))
			      "Thanks.  Now I know better.")))))))

(define (make-branch q y n)
  (list 'branch q y n))

(define (make-leaf a)
  (list 'leaf a))

(define animal-list
  (make-branch "Does it have wings?"
	       (make-leaf 'parrot)
	       (make-leaf 'rabbit)))


(define (animal-game) (animal animal-list))