[plt-scheme] Wierd bug - is it me or PLT's fault?

From: ifconfig (nslookupifconfig at hotmail.com)
Date: Mon Mar 29 04:01:16 EST 2004

Hehe, never mind, I unintentionally had a variable named if :\


> -----Original Message-----
> From: plt-scheme-admin at list.cs.brown.edu [mailto:plt-scheme-
> admin at list.cs.brown.edu] On Behalf Of ifconfig
> Sent: Monday, March 29, 2004 10:50 AM
> To: PLT Scheme
> Subject: [plt-scheme] Wierd bug - is it me or PLT's fault?
> 
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 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


Posted on the users mailing list.