From: Nic Ferrier <nferrier@ferrier.me.uk>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: non-local exits with signal and condition-case
Date: Sun, 02 Jun 2013 22:33:48 +0100 [thread overview]
Message-ID: <87ehckjiyr.fsf@ferrier.me.uk> (raw)
In-Reply-To: <jwvfvx0icds.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sun, 02 Jun 2013 14:52:24 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Could you explain in more detail what you do that doesn't work well
> with catch?
I'll use a specific example (but it really is indicative, I find this
happens to me more often that not doing non-local exits).
This is a heavily simplified version of something I just wrote for the
new elnode based emacswiki:
(defun make-page (page-name)
(let ((buf (find-file-noselect page-name)))
(with-current-buffer buf
(when (re-search-forward "^REDIRECT \\(.*\\)" nil t)
(throw :redirect (match-string 1))))
;; Otherwise we need to send the page
(start-page buf)
(send-page (buf->html buf))))
(defun serve-page (http)
(let ((page-name (get-page http)))
(let ((value
(catch :redirect
(make-page page-name))))
(when value
(send-redirect http value)))))
Note how the throw is being used to communicate place and value but in
the catch I only need to know that there was an exceptional condition.
This is the essence of the problem I think. catch does not support, of
itself, exceptional conditions. You have to overlay support for them
with extra typing.
In this example, I could be in trouble is make-page ever returns
anything. So I could throw a cons with a type indicator (say, :redirect)
and check for the type in the when. But that is a lot more work.
I've played with making macros around catch but in the end they seem
little better than having a signal. Is there a technical reason why a
signal is bad compared to catch/throw?
> BTW, you might like the `cl-return' macro as well
> (to use within `cl-block's).
I strongly dislike sprinkling cl- namespace through my code. It makes it
much less readable to me.
>> (defmacro defsignal (err-symbol inherits-list message)
>> (let ((errv (make-symbol "err-v")))
>> `(let ((,errv ,err-symbol))
>> (put ,errv
>> 'error-conditions
>> (quote ,inherits-list))
>
> You probably want to cons `errv' in front of inherits-list.
I thought about that before I sent it - I think you are probably
right. But my understanding is that you don't need the symbol to be
present; you can disassociate the symbol used to send the signal from
the symbol(s) used to capture it.
I think (as you suggest) a define-signal form should probably not support that
directly because it seems quite counter intuitive.
> FWIW, I wouldn't mind introducing such a macro. Not for the use of
> non-local exits, but to make it easier to define new error conditions.
>
> I would also welcome changes to make the "error-message" part more
> flexible (e.g. be able to use a function, maybe).
>
>> I'm not sure where to put this.
>
> We could add it to subr.el (tho I'd call it define-signal).
Shall I send patches then?
Nic
next prev parent reply other threads:[~2013-06-02 21:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-02 16:24 non-local exits with signal and condition-case Nic Ferrier
2013-06-02 18:52 ` Stefan Monnier
2013-06-02 21:33 ` Nic Ferrier [this message]
2013-06-03 0:02 ` Stefan Monnier
2013-06-03 15:54 ` Davis Herring
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/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ehckjiyr.fsf@ferrier.me.uk \
--to=nferrier@ferrier.me.uk \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).