<< Previous exercise (4.51) | Index | Next exercise (4.53) >>


 ;; add this in analyze 
 ((if-fail? expr) (analyze-if-fail expr)) 
 ;; add those to amb evaluator 
 (define (if-fail? expr) (tagged-list? expr 'if-fail)) 
  (define (analyze-if-fail expr) 
   (let ((first (analyze (cadr expr))) 
         (second (analyze (caddr expr)))) 
    (lambda (env succeed fail) 
     (first env 
            (lambda (value fail2) 
             (succeed value fail)) 
            (lambda () 
             (second env succeed fail)))))) 

The success continuation needs to be (succeed value fail2) and not (succeed value fail). Otherwise, try-again will not return new values even when there are some left.