(load "lab2x.ss")
(define reduce-count
(lambda (exp)
;returns a pair, w/ car being the answer, cdr the count
; of how many reductions it took to reach the answer
(define loop
(lambda (exp prior-reductions-count)
(reduce-once-appl exp
(lambda (reduced-exp)
(loop reduced-exp
(+ prior-reductions-count
1)))
(lambda ()
(cons exp
prior-reductions-count)))))
(loop exp 0)))
(define repl
(lambda ()
(display "-> ")
(let ((exp (parse (read))))
(let ((eval-result (reduce-count exp)))
(let ((count (cdr eval-result))
(answer (unparse (car eval-result))))
(display "After ")
(write count)
(display " reductions, reached ")
(write answer)
(newline))))
(repl)))