[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Procedure proposal: call-with-escape-procedure
From: |
Martin Grabmueller |
Subject: |
Procedure proposal: call-with-escape-procedure |
Date: |
Fri, 02 Mar 2001 17:01:06 +0100 |
Hello list,
I often find an escape procedure useful when writing Scheme code, such
as for early exits on success, on error or for other reasons. Since
`call/cc' is too general (and too expensive in Guile), and using
`catch' and `throw' is too clumsy for my taste, I tried to find a
better and generally useful alternative.
Therefore I propose to include the following procedure into ice-9:
(define (call-with-escape-procedure proc)
(letrec ((key (gensym "call/ec"))
(escape (lambda val (throw key val))))
(catch key
(lambda ()
(proc escape))
(lambda (k val-list)
(apply values val-list)))))
(define call/ec call-with-escape-procedure)
`call/ec' calls `proc' and passes it an escape procedure, which, when
called with arbitrarily many arguments, will pass these arguments to
the continuation of the call to `call/ec'. When the escape procedure
is called from another dynamic scope than from inside the
corresponding call to `call/ec', an exception is thrown. Note that
the continuation for the call to `call/ec' must expect as many values
as passed to the escape procedure.
If nobody objects, I would like to add this procedure to a new module
in the ice-9 directory called (ice-9 call-ec). Maybe it would be
useful to load the module by default too, but YMMV.
Regards,
'martin
- Procedure proposal: call-with-escape-procedure,
Martin Grabmueller <=
- Re: Procedure proposal: call-with-escape-procedure, Marius Vollmer, 2001/03/03
- Re: Procedure proposal: call-with-escape-procedure, Marius Vollmer, 2001/03/03
- Re: Procedure proposal: call-with-escape-procedure, Martin Grabmueller, 2001/03/05
- Re: Procedure proposal: call-with-escape-procedure, Marius Vollmer, 2001/03/05
- Re: Procedure proposal: call-with-escape-procedure, Marius Vollmer, 2001/03/05
- Re: Procedure proposal: call-with-escape-procedure, Martin Grabmueller, 2001/03/06
- Re: Procedure proposal: call-with-escape-procedure, Marius Vollmer, 2001/03/06
- Re: Procedure proposal: call-with-escape-procedure, Martin Grabmueller, 2001/03/06
- Re: Procedure proposal: call-with-escape-procedure, Marius Vollmer, 2001/03/06
- Re: Procedure proposal: call-with-escape-procedure, Miroslav Silovic, 2001/03/06