unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Chris Vine <vine35792468@gmail.com>
To: guile-user@gnu.org
Subject: Re: "Missing" libraries/concepts found in other languages/ecosystems?
Date: Sat, 11 Jul 2020 11:13:59 +0100	[thread overview]
Message-ID: <20200711111359.acacd7d4a6b328bab44ba11e@gmail.com> (raw)
In-Reply-To: <14a24bd8-2664-c7bf-eff8-ca3f4e068ef8@posteo.de>

On Sat, 11 Jul 2020 02:19:43 +0200
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
[snip]
> I would be glad, if any non-optimal example was extended or updated by a
> more knowledgeable person or I was told what I could improve in some
> example. The examples in the repository are only, what I was able to
> understand and I often find myself looking up, how to do something again.
> 
> If anyone wants to take any example and put it in the docs, go ahead.
> Only don't think that my examples are the last word on how to do things.
> Far from it!
> 
> About the exceptions thing: Aha! I should look into that again. I
> thought the "conditions" thing was already pretty cool and useful. Once
> an exception happens, you can react on it. I did not understand the
> "call/ec helper" part, but perhaps I can understand it, when I check the
> docs for the new exceptions in Guile 3.

The issue is that "non-continuable" in "non-continuable exception" does
not mean an exception that the program cannot survive, it means an
exception for which, after handling, control cannot return to the point
at which the exception was raised[1].  (To answer the question in your
following email, continuable exceptions are in some sense analogous to
common lisp restarts.)  Most guile exceptions are non-continuable.  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.

With R6RS/R7RS's with-exception-handler, for non-continuable exceptions
the handler procedure should normally therefore either invoke a call/ec
continuation object to unwind the stack to the point where the
exception is handled, or it should (after it has done what it is
intended to do) re-raise the exception to be handled and/or unwound
elsewhere.  Guile-3.0's with-exception-handler procedure will do the
former for you automatically if you set its #:unwind? argument to
true.  The nearest to guile-2.2's catch expression in guile-3.0's
exception system is to use with-exception-handler with #:unwind? set
as #t.  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. 

I therefore suggest that your first example using
with-exception-handler should set #:unwind? to #t so that the program
does not end with a &non-continuable exception.  I also suggest that,
if intended for guile-3.0 and not guile-2.2, you should use guile's
exception objects rather than R6RS conditions (basically you use
'make-exception' instead of 'condition' - the two are in effect the
same).

If intended also for guile-2.2 the other issue is that its R6RS/R7RS
exception procedures can only handle R6RS/R7RS exceptions emitted by
raise or raise-continuable, and not guile exceptions raised by throw.
This means that your divide by 0 example will not work in guile-2.2.

Chris

[1]  Microsoft in its C++ and .NET languages amalgamates machine
exceptions, and some signal exceptions, with language exceptions.  In
their nomenclature "non-continuable exception" does mean an exception
that the program cannot survive, such as SIGSEGV or an irrecoverable
hardware exception.  This is not however its general meaning.  Most
languages do not have continuable exceptions.  Scheme, common lisp and
smalltalk do.



  parent reply	other threads:[~2020-07-11 10:13 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 [this message]
2020-07-11 18:20             ` John Cowan
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=20200711111359.acacd7d4a6b328bab44ba11e@gmail.com \
    --to=vine35792468@gmail.com \
    --cc=guile-user@gnu.org \
    /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).