all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* to big nest level of recursion
@ 2006-03-20 12:35 Anton V. Belyaev
  2006-03-20 12:45 ` Hans-Christoph Wirth
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Anton V. Belyaev @ 2006-03-20 12:35 UTC (permalink / raw)


Hi! I wrote a simple function which fails on lists long enougth with
reason "(error "Lisp nesting exceeds `max-lisp-eval-depth'")". But the
function contains right recursion. Does Emacs LISP interpreter unwind
right recursion calls?

(defun contains (lst el)
  (if (null lst)
      nil
    (if (eq (car lst) el)
	t
      (contains (cdr lst) el)
      )
    )
  )

PS: Does Emacs built-in functions have an equivalent of my contains?

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: to big nest level of recursion
@ 2006-03-21 21:31 David Reitter
  0 siblings, 0 replies; 10+ messages in thread
From: David Reitter @ 2006-03-21 21:31 UTC (permalink / raw)
  Cc: anton.belyaev


[-- Attachment #1.1: Type: text/plain, Size: 680 bytes --]

> 2) Pascal Bourguignon mentioned TCO. Is it relatively right recursion
> handling? Why does it works only with boolean expressions? I thought
> that it is enougth to make recursive call the last in the expression
> (as it is in Haskell). Where can I read about it?

TCO = tail call optimization, just what you were referring to.

In Prolog, I'd formulate the algorithm just like you did. In elisp,  
you can't, because stack size is small and there is obviously no TCO.

http://en.wikipedia.org/wiki/Tail_recursion

Maybe it's a consolation for you that for every recursive algorithm,  
you can formulate an iterative version. And you don't bloat a call  
stack when you do so.


[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2454 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <mailman.21.1142976703.14011.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2006-04-04 13:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-20 12:35 to big nest level of recursion Anton V. Belyaev
2006-03-20 12:45 ` Hans-Christoph Wirth
2006-03-20 12:51 ` David Kastrup
2006-03-20 13:52 ` Pascal Bourguignon
2006-03-20 15:56   ` Anton V. Belyaev
2006-03-21 17:09     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2006-03-21 21:31 David Reitter
     [not found] <mailman.21.1142976703.14011.help-gnu-emacs@gnu.org>
2006-03-25 10:30 ` Alan Mackenzie
2006-03-25 11:46   ` David Kastrup
2006-04-04 13:36     ` david.reitter

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.