(require (lib "process.ss")
)
(require (lib "etc.ss"))
(define (gen-exprs count)
(build-list count (lambda (i) (generate-expression 2))))
(define expr-list (gen-exprs 1000))
(with-output-to-file "exprs.ss"
(lambda ()
(for-each (lambda (expr) (printf "~a~n" expr)) expr-list)
(newline)))
(with-output-to-file "exprs.py"
(lambda ()
(printf "#!/usr/bin/python~n~n")
(for-each (lambda (expr)
(printf "try:~n")
(printf " print ~a~n" (prefix->infix expr))
(printf "except ZeroDivisionError:~n")
(printf " print \"division by 0 in ~a\"~n"
(prefix->infix expr)))
expr-list)
(newline)))
(with-output-to-file "expr-results.txt"
(lambda ()
(for-each (lambda (expr)
(with-handlers ((exn:application:divide-by-zero?
(lambda (exn)
(printf "division by 0"))))
(printf "~a~n" (eval expr))))
expr-list)
(newline)))
(system "chmod +x exprs.py")
(system "./exprs.py > expr-results-py.txt")
(system "diff -b expr-results.txt expr-results-py.txt > expr-diff.txt")