[plt-scheme] Wierd bug - is it me or PLT's fault?
I have a piece of code that opens an output file:
It tries to open it. If it fails, it asks whether to overwrite or not, then
tries again.
If it succeeds (in the first or second attempt) it sets current-output-port.
I've run it in its own module, and it works perfectly.
But when I run it inside the module that it's supposed to go into, both
branches of an if statement get executed!
(module testof mzscheme
(require (lib "mred.ss" "mred"))
(define of "test.txt")
;;; here starts the piece of code
(with-handlers
([exn:i/o? (lambda (e)
(message-box "Brainfuck"
(format "Error: Could not open output file
~a; using standard output\n" of)
#f
`(ok caution)))])
(current-output-port
(with-handlers
([exn:i/o? (lambda (e)
(if (equal? (message-box "Brainfuck"
(format "File ~a
exists, overwrite?" of)
#f
`(yes-no))
'yes)
(begin (display "yes\n") (open-output-file of
'truncate/replace))
(begin (display "no\n") (raise e))))])
(open-output-file of))))
;;; and here it ends
(display "Hello.\r\n")
(close-output-port (current-output-port)))
Now, notice the (display "yes\n") and (display "no\n") - in this example
only one is printed - depending on what you select in the message-box. But
when I run it in my piece of code, whether I choose yes or no it prints
"yes", opens the file, then prints "no" and uses standard output - what
could cause this?
Yours,
ifconfig