bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#47677: [PATCH] condition-case success continuation


From: Mattias Engdegård
Subject: bug#47677: [PATCH] condition-case success continuation
Date: Mon, 26 Apr 2021 13:53:26 +0200

25 apr. 2021 kl. 18.45 skrev Lars Ingebrigtsen <larsi@gnus.org>:

> condition-case is about handling errors -- it can be used as a general
> flow control system, but that's an awkward fit.  It conveys intention.
> So I don't think we should extend it to handle more throw/catch-like
> things.

Most other languages use the same exception system for both errors and 
'throws'; the distinction in Lisp is an artefact of history. Both are 
dynamically-scoped single-shot upwards-only value-conveying non-local control 
transfers (or described in continuation terms with about as many adjectives). 
The differences are minor.

Several times I've had to hack around the inability of `catch` to distinguish 
throws from normal termination and could go on doing so, but it feels like 
making function calls by manual variable assignment, stack operations and 
jumps. The byte code has no trouble expressing a more useful catch; it's just 
an arbitrary restriction in our Lisp primitives.

In addition, `catch` and `condition-case` don't compose. It would be 
interesting to design primitives that do but since that seems tricky (prove me 
wrong!), a unified `condition-case` does the job with a minimum of fuss and is 
definitely not a hack.

> However, I do agree that Emacs Lisp could need some beefing up in the
> "early return" department

Yes! But catch/throw is good for getting out of deep function call chains which 
is not quite the same thing. They are hard to optimise well for local use 
(exiting a loop or function) because it is difficult to prove the absence of 
throws elsewhere.

A variant of block/return-from would do, but better optimisations for local 
functions (TCO in particular) may be at least as useful.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]