* bug#748: Elisp: lexical-let and cyclic structures
@ 2008-08-20 13:57 Michael Heerdegen
2008-08-21 1:12 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Michael Heerdegen @ 2008-08-20 13:57 UTC (permalink / raw)
To: emacs-pretest-bug
When using the reader constructs `#N=' and `#N#' for cyclic
structures, lexical-let sometimes produces errors which don't occur
with let.
Example: Eval the following:
(defun f (start)
(lexical-let (start start) ;; return a closure
#1=(lambda (x) (if (= x start) x
(+ x (#1# (1- x)))))))
Then evaluating f ends with an error:
(f 3)
"Variable binding depth exceeds max-specpdl-size"
The problem also occurs without lambdas. Examples:
(let () '#1=(#1#)) ;; ==> (#0)
(lexical-let () '#1=(#1#)) ;; Error
(let ((x '#1=(#1#))) (lexical-let () x)) ;; ==> (#0)
`#1=(#1#) ;; Error
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#748: Elisp: lexical-let and cyclic structures
2008-08-20 13:57 bug#748: Elisp: lexical-let and cyclic structures Michael Heerdegen
@ 2008-08-21 1:12 ` Stefan Monnier
2011-07-09 17:51 ` Glenn Morris
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2008-08-21 1:12 UTC (permalink / raw)
To: 748
tag +748 wontfix
thanks
> When using the reader constructs `#N=' and `#N#' for cyclic
> structures, lexical-let sometimes produces errors which don't occur
> with let.
Most programming languages do not accept infinite programs. Elisp is
no exception. The fact that you can build cyclic abstract syntax trees
and that they sometimes get evaluated correctly is just an accident.
I.e. if it hurts, don't do it.
> (defun f (start)
> (lexical-let (start start) ;; return a closure
> #1=(lambda (x) (if (= x start) x
> (+ x (#1# (1- x)))))))
For this case, I'd recommend to make the recursion explicit, e.g.:
(defun f (start)
(lexical-let ((start start)) ;; return a closure
(labels ((loop (x) (if (= x start) x
(+ x (loop (1- x))))))
loop)))
-- Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#748: Elisp: lexical-let and cyclic structures
2008-08-21 1:12 ` Stefan Monnier
@ 2011-07-09 17:51 ` Glenn Morris
0 siblings, 0 replies; 3+ messages in thread
From: Glenn Morris @ 2011-07-09 17:51 UTC (permalink / raw)
To: 748-done
I don't see a need to keep open this particular report, which was marked
"wontfix" some time ago.
Stefan Monnier wrote:
> Most programming languages do not accept infinite programs. Elisp is
> no exception. The fact that you can build cyclic abstract syntax trees
> and that they sometimes get evaluated correctly is just an accident.
>
> I.e. if it hurts, don't do it.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-09 17:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-20 13:57 bug#748: Elisp: lexical-let and cyclic structures Michael Heerdegen
2008-08-21 1:12 ` Stefan Monnier
2011-07-09 17:51 ` Glenn Morris
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).