From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nic Ferrier Newsgroups: gmane.emacs.devel Subject: Re: non-local exits with signal and condition-case Date: Sun, 02 Jun 2013 22:33:48 +0100 Message-ID: <87ehckjiyr.fsf@ferrier.me.uk> References: <87ip1wjx9s.fsf@ferrier.me.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1370208846 24527 80.91.229.3 (2 Jun 2013 21:34:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Jun 2013 21:34:06 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 02 23:34:05 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UjFud-0001qL-HP for ged-emacs-devel@m.gmane.org; Sun, 02 Jun 2013 23:34:03 +0200 Original-Received: from localhost ([::1]:45986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjFud-0004wT-0U for ged-emacs-devel@m.gmane.org; Sun, 02 Jun 2013 17:34:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjFuX-0004wO-Dh for emacs-devel@gnu.org; Sun, 02 Jun 2013 17:34:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjFuU-000628-W4 for emacs-devel@gnu.org; Sun, 02 Jun 2013 17:33:57 -0400 Original-Received: from static.17.66.46.78.clients.your-server.de ([78.46.66.17]:40164 helo=po1.ferrier.me.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjFuU-00061l-PZ for emacs-devel@gnu.org; Sun, 02 Jun 2013 17:33:54 -0400 Original-Received: from nferrier (140.35.155.90.in-addr.arpa [90.155.35.140]) by po1.ferrier.me.uk (Postfix) with ESMTP id 3E53BAC00A5; Sun, 2 Jun 2013 23:34:00 +0200 (CEST) Original-Received: from nferrier (localhost [127.0.0.1]) by nferrier (Postfix) with ESMTPS id D58CE1600B7; Sun, 2 Jun 2013 22:33:48 +0100 (BST) In-Reply-To: (Stefan Monnier's message of "Sun, 02 Jun 2013 14:52:24 -0400") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 78.46.66.17 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160011 Archived-At: Stefan Monnier 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