all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* flet not undone on lisp nesting error
@ 2010-02-27 20:22 Dan Davison
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Davison @ 2010-02-27 20:22 UTC (permalink / raw
  To: help-gnu-emacs

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

--8<---------------cut here---------------start------------->8---
(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
--8<---------------cut here---------------end--------------->8---




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: flet not undone on lisp nesting error
       [not found] <mailman.2053.1267396226.14305.help-gnu-emacs@gnu.org>
@ 2010-03-01  1:01 ` Stefan Monnier
  2010-03-01  1:03 ` Pascal J. Bourguignon
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2010-03-01  1:01 UTC (permalink / raw
  To: help-gnu-emacs

> 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?

Looks like a bug.  Please report it via M-x report-emacs-bug.


        Stefan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: flet not undone on lisp nesting error
       [not found] <mailman.2053.1267396226.14305.help-gnu-emacs@gnu.org>
  2010-03-01  1:01 ` Stefan Monnier
@ 2010-03-01  1:03 ` Pascal J. Bourguignon
  1 sibling, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2010-03-01  1:03 UTC (permalink / raw
  To: help-gnu-emacs

Dan Davison <davison@stats.ox.ac.uk> 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__


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-01  1:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-27 20:22 flet not undone on lisp nesting error Dan Davison
     [not found] <mailman.2053.1267396226.14305.help-gnu-emacs@gnu.org>
2010-03-01  1:01 ` Stefan Monnier
2010-03-01  1:03 ` Pascal J. Bourguignon

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.