unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: John Cowan <cowan@ccil.org>
To: Chris Vine <vine35792468@gmail.com>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: "Missing" libraries/concepts found in other languages/ecosystems?
Date: Sat, 11 Jul 2020 14:20:22 -0400	[thread overview]
Message-ID: <CAD2gp_R9=PhErzDoRMiOUH1DuNJBDOSKZc+tJ3xg_ryZjO-cAg@mail.gmail.com> (raw)
In-Reply-To: <20200711111359.acacd7d4a6b328bab44ba11e@gmail.com>

On Sat, Jul 11, 2020 at 6:14 AM Chris Vine <vine35792468@gmail.com> wrote:


> (To answer the question in your
> following email, continuable exceptions are in some sense analogous to
> common lisp restarts.)


Continuable and non-continuable in Scheme are exactly like CL raise and
error (and its variants), except that the machinery is different.  Restarts
are another matter, independent of the condition system (though often
considered with it).  I have a pre-SRFI for them at <
https://github.com/johnwcowan/r7rs-work/blob/master/RestartsCowan.md>,
similar to but simpler than the CL restart system, and using first-class
restarts.  It currently lacks restart-case.

The point arising from this is that in the case of a non-continuable
> exception the handler procedure passed to with-exception-handler must
> not return, or a &non-continuable exception will be raised when
> control does attempt to return.
>

In CL the exact machinery is different: a CL handler refuses to handle a
condition by returning.  A continuable exception must use a non-local exit
to get back to the signaler, whereas an unhandled non-continuable exception
drops into the semi-standardized facility called the debugger.


> R6RS/R7RS's guard form is a wrapper for this which also
> incorporates a cond form to enable different exception types to be
> handled by different handlers.
>

Is the intention to provide `guard` in Guile 3.x?

I think common lisp restarts are by and large useless.  They rely on
> the assumption that the caller of a procedure which throws knows better
> how to handle an exception arising in that procedure than the procedure
> itself.  That is rarely the case.  Usually the code at the site of the
> error should do what it can to remedy the problem and then (if it cannot
> be fully rectified) throw an exception which unwinds the stack, for the
> exception to be picked up elsewhere.


Here's a straightforward example of restarts in action.  Suppose a library
reads a file in a format known to itself, performs some complex in-memory
transformations of the data, and then writes the data to another or the
same file in the same format. Of course the files may be inaccessible to
the library for whatever reasons, and some kind of recovery is needed.

The usual approach is to export three procedures: one to read the input
file and return the data in an opaque internal format, one to process the
data and return the transformed data, and one to write the output file.
Any of them may throw exceptions if something goes wrong.  However, this
exposes the internal data format to the caller, and requires the caller to
strictly follow the input-process-output sequence of calls, a tiny design
pattern.

With continuable exceptions plus restarts, however, there can be just one
exposed procedure which is passed an input file name and an output file
name which does it all.  If any of the I/O components fail, a continuable
exception can be raised which when handled invokes a restart (of type
"use-value") with the name of a replacement file name to use instead.

As a result, the opaque data is now always concealed from the caller, but a
write failure does not require the already-transformed data to be
recomputed.  Just as a condition communicates information from a signaler
(which knows what is wrong) to a handler (which knows what to do), a
restart communicates information from the handler (which knows what should
be done) back to the signaler (which knows how to do it).



John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
All Norstrilians knew that humor was "pleasurable corrigible malfunction".
        --Cordwainer Smith, Norstrilia


  reply	other threads:[~2020-07-11 18:20 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.75.1594224014.21222.guile-user@gnu.org>
2020-07-08 18:22 ` "Missing" libraries/concepts found in other languages/ecosystems? Zelphir Kaltstahl
2020-07-09 18:12   ` Leo Butler
2020-07-09 19:34     ` Zelphir Kaltstahl
2020-07-10  7:39   ` Aleix Conchillo Flaqué
2020-07-10  8:14     ` Alex Sassmannshausen
2020-07-10  8:49   ` Catonano
2020-07-10 10:21     ` Chris Vine
2020-07-10 11:20       ` Catonano
2020-07-11  0:19         ` Zelphir Kaltstahl
2020-07-11  0:34           ` Zelphir Kaltstahl
2020-07-11 10:14             ` Chris Vine
2020-07-11 13:45               ` Stefan Israelsson Tampe
2020-07-11 14:46             ` Linus Björnstam
2020-07-11 10:13           ` Chris Vine
2020-07-11 18:20             ` John Cowan [this message]
2020-07-11 22:39               ` Chris Vine
2020-07-11 22:41                 ` John Cowan
2020-07-11 23:09                   ` Chris Vine
2020-07-12  1:52                     ` John Cowan
2020-07-12 20:26                       ` Chris Vine
2020-07-13 10:10                 ` Chris Vine
2020-07-12 16:08             ` Catonano
2020-07-12 16:10               ` Catonano
2020-07-12 17:46               ` John Cowan
2020-07-12 19:14               ` Chris Vine
2020-07-12 19:32                 ` Chris Vine
2020-07-14 10:32                   ` Catonano
2020-07-14 11:06                     ` Catonano
2020-07-14 16:21                     ` Chris Vine
2020-07-12 20:33               ` Zelphir Kaltstahl
2020-07-08  7:38 Simen Endsjø
2020-07-08  8:15 ` Vladimir Zhbanov
2020-07-08 10:08 ` Catonano
2020-07-08 11:29 ` Chris Vine
2020-07-10 12:15 ` Christopher Lam
2020-07-10 15:52   ` Chris Vine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAD2gp_R9=PhErzDoRMiOUH1DuNJBDOSKZc+tJ3xg_ryZjO-cAg@mail.gmail.com' \
    --to=cowan@ccil.org \
    --cc=guile-user@gnu.org \
    --cc=vine35792468@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).