Alain MELLAN <alain.mellan@st.com> wrote:
+---------------
| guile> (go)
| code before abort
| ; Aborting...
| ERROR: In procedure primitive-load in expression (primitive-load name):
| ERROR: Wrong type argument in position 1: #<closed: file 0>
| ABORT: (wrong-type-arg)
+---------------
Aha! It gets more interesting! When I tried it in SCM 4e1 (and in MzScheme),
I had *pasted* the code you gave into the top-level REPL, and it worked fine.
But when I put it in a file and "load" it, I get a similar error message to
yours:
% scm
...chatter...
> (load "abort.scm")
#<unspecified>
> (go)
code before abort
; Aborting...
ERROR: read: Wrong type in arg1 #<input-port closed>
>
And indeed, I got the same error from MzScheme, when using the "load":
> (load "abort.scm")
> (go)
code before abort
; Aborting...
#<primitive:get-port-char>: input port is closed
>
It would appear that the continuation that gets captured during a "load"
also captures the port that is being used to "read" the loading file
(which, in retrospect, sort of makes sense, since a "load" is a kind of
"with-input-with-file"), and thus any attempt to restart that continuation
after the "load" finishes will fail.
However, if you change the initialization of the global variable "*abort*"
in the file from:
(define *abort* '())
(call/cc (lambda (cont) (set! *abort* cont)))
to:
(define *abort* '())
(define (init-abort)
(call/cc (lambda (cont) (set! *abort* cont))))
and then call "init-abort" from the top-level REPL, *not* during the "load",
then it all works (in both SCM 4e1 and Mzscheme, and I suspect Guile as well),
and you can re-use the continuation multiple times:
> (load "abort.scm")
> (init-abort)
> (go)
code before abort
; Aborting...
#f
> (go)
code before abort
; Aborting...
#f
>
Aren't continuations "fun"?
+---------------
| With SCM, that gives:
| ==> (go)
| code before abort
| ; Aborting...
|
| ERROR: segment violation
+---------------
As someone else wrote, that could be a problem with CHEAP-CONTINUATIONS...
-Rob
-----
Rob Warnock, 7L-551 rpw3@sgi.com http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673 [New area code!]
2011 N. Shoreline Blvd. FAX: 650-933-4392
Mountain View, CA 94043 PP-ASEL-IA