|
From: Timothy H. <tim...@ma...> - 2003-01-17 04:46:09
|
On Thursday, January 16, 2003, at 10:02 PM, Derek Upham wrote:
> I'm getting the following two behaviors with "call/cc". The first one
> is correct. The second one fails when jumping out of a nested
> "tryFinally". Is this a known problem?
We haven't had much use for call/cc as the Jscheme implementation is a
weakened form equivalent to
tryCatch.
The following "implementations" actually perform a little better with
your examples:
> (define (call/ec K)
> (tryCatch
> (K (lambda(y) (throw y)))
> (lambda(e) e)))
>
> (define-macro (tryFinally A B)
> `(jsint.Procedure.tryFinally (lambda() ,A) (lambda() ,B)))
>
where I'm using call/ec for call with escape continuation,
to emphasize that this is not full call/cc.
This implementation behaves more like you would expect:
> > (call/ec (lambda(exit) (tryFinally (+ 3 5) (display {\nfoo\n}))))
>
> foo
> 8
> > (call/ec (lambda(exit) (tryFinally (/ 1 0) (display {\nfoo\n}))))
>
> foo
> java.lang.ArithmeticException: / by zero
>
Note that the call/ec catches the exception thrown by (/ 1 0).
Note that in (tryFinally A B)
the result returned is that returned by A (or is the exception thrown
by A),
but tryFinally guarantees that (B) will be evaluated after the
value of A is computed and before the result is returned (or thrown).
This would seem to be the most useful behavior, e.g. when you want to
make
sure that a socket or file is closed before leaving a procedure.
---Tim---
> This would be with CVS sources a week or two old.
>
>
>> (call-with-current-continuation (lambda (exit) (exit (+ 3 5))))
> 8
>> (call-with-current-continuation (lambda (exit) (tryFinally (exit (+ 3
>> 5)) 'foo)))
>
> (public static java.lang.Object
> jsint.Procedure.tryFinally(java.lang.Object,java.lang.Object)
> ({jsint.Closure ??[0] ()} {jsint.Closure ??[0] ()} ))
>
> ====================================
> java.lang.RuntimeException: continuation
>
>
> Thanks,
>
> Derek
>
> --
> Derek Upham
> Senior Software Engineer
> Ontain
> 1750 112th Ave NE, Suite C-245
> Bellevue, WA 98004-3727
> Tel: 425-460-1886
> der...@on...
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by: Thawte.com
> Understand how to protect your customers personal information by
> implementing
> SSL on your Apache Web Server. Click here to get our FREE Thawte Apache
> Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en
> _______________________________________________
> Jscheme-user mailing list
> Jsc...@li...
> https://lists.sourceforge.net/lists/listinfo/jscheme-user
>
|