From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: flet not undone on lisp nesting error Date: Mon, 01 Mar 2010 02:03:12 +0100 Organization: Informatimago Message-ID: <87r5o497lb.fsf@galatea.lan.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1267407732 28808 80.91.229.12 (1 Mar 2010 01:42:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 1 Mar 2010 01:42:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 01 02:42:08 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Nlue7-0003np-NR for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Mar 2010 02:42:08 +0100 Original-Received: from localhost ([127.0.0.1]:41580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nlue6-0004au-Uz for geh-help-gnu-emacs@m.gmane.org; Sun, 28 Feb 2010 20:42:06 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 49 Original-X-Trace: individual.net YfVy5vLvwfpgC15EcCt1/AgK/wCWnexPqNbrTkdnkMov8ZMTm/ Cancel-Lock: sha1:ZDNlNTQ0Y2Y2ZjY0OTc4MWIxY2E5NWRjZWQ2YWQ0YTYyNzZmMjUxMA== sha1:xWkQ7OSRSWq7ljdChD2rXU94+6k= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:177217 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72257 Archived-At: Dan Davison writes: > If I trigger a lisp nesting error with an infinite recursion inside a > let and an flet binding, then the effects of the flet are not undone, > resulting in a change of binding at the top-level. (Code below; the > effects of the let are undone). > > However, if I trigger a "normal" error with (error) then both are > undone. Is this peculiar to a circular lisp nesting error, or are there > other classes of error upon which flet will not be undone? What is the > idiomatic way to protect against this (other than not having infinite > recursions in my code)? Do I have to keep copies of the original values > for use in an unwind-protect? > > Dan > > (defun g () 'g-orig) > (setq a 'a-orig) > > (defun h () > (let ((a 'a-new)) > (flet ((g () 'g-new)) > (h)))) > (h) ;; <-- Lisp nesting exceeds `max-lisp-eval-depth' > (g) ;; 'g-new ! > a ;; a-orig > > (defun g () 'g-orig) > (setq a 'a-orig) > (defun f () > (let ((a 'a-new)) > (flet ((g () 'g-new)) > (error "Error!")))) > > (f) > (g) ;; <-- 'g-orig > a ;; <-- 'a-orig There is no true lexical binding in emacs, and this includes functions. flet is a macro that simulates it with gensym'ed symbols and using unwind-protect to restore the binding to g. I guess that when there's an out of stack error, the cleanup clauses of unwind-protect are not called. At least in your version of emacs. In my emacs-version "23.1.1", it seems to clean up correctly (and correctly restore the fbinding of g). -- __Pascal Bourguignon__