|
From: | Michael Heerdegen |
Subject: | Re: Help with recursive destructive function |
Date: | Sat, 05 May 2018 17:41:41 +0200 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
I wrote: > I guess I would use an iterator: the definition would still looks > recursive, but the execution isn't problematic any more if done right. Here is an example: #+begin_src emacs-lisp (iter-defun iter-tree-example (tree) (cl-loop for thing in-ref tree by #'cdr do (if (consp thing) (iter-yield-from (iter-tree-example thing)) (iter-yield (ignore (when (stringp thing) (cl-callf upcase thing))))))) (let ((tree '("a" 1 ("b" "c" ("d")) "e"))) (iter-do (_ (iter-tree-example tree))) tree) ==> ("A" 1 ("B" "C" ("D")) "E") (let ((huge-list (number-sequence 1 100000))) (setcdr (last huge-list) (cons "a" nil)) (iter-do (_ (iter-tree-example huge-list))) (ignore huge-list)) |-- takes some time but doesn't crash #+end_src Yield values don't have any purpose but I guess without yielding you would get no CPS rewrite but a standard recursive function that would be problematic with the HUGE-LIST. Michael.
[Prev in Thread] | Current Thread | [Next in Thread] |