lib/mjadud/test-p-i.ss
;
(require (lib "process.ss")
         )
;
; (define PY_EXE "/usr/bin/python -c")
;
; (define (test-python-expr expr)
;   (let-values (((in-from-py out-to-py pid err-from-py py-control)
;                 (apply values (process (string-append PY_EXE " " expr)))))
;     (let ((result (read in-from-py)))
;       result)))
;
; (define (t2 expr)
;   (system (string-append PY_EXE " " expr)))

(require (lib "etc.ss"))        ;; build-list

(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")