shhyou / ypsilon-fork

Automatically exported from code.google.com/p/ypsilon
Other
0 stars 0 forks source link

call-with-input-file does not close its port with guard and raise-continuable #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When the current exception handler is installed by with-exception-handler, 
it seems well as follows:

$ cat x
(x)
$ ypsilon
Ypsilon 0.9.6-update2 Copyright (c) 2008 Y.Fujita, LittleWing Company 
Limited.
> (let ((foo #f))
  (with-exception-handler
   (lambda (e) #t)
   (lambda ()
     (call-with-input-file "x"
       (lambda (iport)
         (set! foo iport)
         (raise-continuable 1)))))
  (get-datum foo))
error in get-datum: expected opened port, but got #<textual-input-port "x" 
utf-8 closed>
backtrace:
  0  (get-datum foo)
  ..."/dev/stdin" line 9
>

But in case of guard:
> (let ((foo #f))
  (guard (e
          (else #t))
    (call-with-input-file "x"
      (lambda (iport)
    (set! foo iport)
        (raise-continuable 1))))
  (get-datum foo))
(x)

Thanks.

Original issue reported on code.google.com by tabe.fix...@gmail.com on 7 Sep 2008 at 5:10

GoogleCodeExporter commented 9 years ago
Thank you for your message.
Regarding the behavior of guard and raise-continuable, I think it is intended 
by R6RS.

What my understanding is:
> (let ((foo #f))
>   (guard (e
>           (else #t))
>          (call-with-input-file "x"
>            (lambda (iport)
>              (set! foo iport)
>              (raise-continuable 1))))
>   (get-datum foo))
* (raise-continuable 1) never returns because (else #t) will be evaluated with 
the
continuation and dynamic environment of the guard expression. It means that the
evaluation of (else #t) causes that the guard expression returns #t immediately.
* Because given procedure does not return, call-with-input-file do not close 
port
automatically.

Please note that I may miss something since I'm not a specialist of Scheme
Programming Language.
Your comments are very welcome. Thank you!

---------
References:
R6RS Standard Libraries - 7.1 Exceptions (guard):
http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-8.html#node_sec_7.1
R6RS Standard Libraries - 8.3 Simple I/O (call-with-input-file):
http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-9.html#node_sec_8.3:
A message by Abdulaziz Ghuloum relate to subject "guard re-raising and 
continuable
exceptions" in [r6rs-discuss]:
http://lists.r6rs.org/pipermail/r6rs-discuss/2008-July/003527.html

Original comment by y.fujita...@gmail.com on 8 Sep 2008 at 4:36

GoogleCodeExporter commented 9 years ago
> A message by Abdulaziz Ghuloum relate to subject "guard re-raising and 
continuable 
exceptions" in [r6rs-discuss]:
> http://lists.r6rs.org/pipermail/r6rs-discuss/2008-July/003527.html
OK, the above one says that it is intended by R6RS, so you are right and this 
issue 
is bogus.
(Anyway the behavior of re-raising an exception may be worthy of attention :)
I'm glad to clarify my misunderstanding by your comment. Thanks a lot.

Original comment by tabe.fix...@gmail.com on 9 Sep 2008 at 2:23

GoogleCodeExporter commented 9 years ago
Thank you for your reply.
Please keep in touch R6RS and Ypsilon!

-- fujita

Original comment by y.fujita...@gmail.com on 9 Sep 2008 at 3:00