[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with recursive destructive function
From: |
Eric Abrahamsen |
Subject: |
Re: Help with recursive destructive function |
Date: |
Sun, 06 May 2018 10:29:39 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Michael Heerdegen <address@hidden> writes:
> 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.
Thanks to both of you! This was some good food for thought. I made
Stefan's suggested change to my original function and it works fine. It
still looks ugly to me because I'm doing the same test-and-set in three
different places, but with sufficient poking I can probably get it all
inside the same loop.
All else being equal I prefer this more "basic" version, simply because
I understand everything that's happening in it. I haven't used `cl-loop'
before, but I assume it's not doing anything that
(while (consp thing)
...
(setq thing (cdr thing))
Isn't doing? Oh, but then you wouldn't be able to use cl-callf directly
on thing.
Recursion is an issue, but the original version recurses on car, not
cdr, which I think (?) is much less of a problem. It went through your
huge-list with no trouble (and faster than the iterative version). I
suppose someone might have accumulated 801 levels of nested quotes in
their Gnus registry (god, I hope not), but otherwise I'm not sure it's a
worry.
On the third hand, if "bulletproof" is the goal, maybe it's best not to
risk it...
> #+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)))))))
> 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.
I guess this works because the calls to `iter-yield' and
`iter-yield-from' fully return from the function? Also, what does "CPS
rewrite" mean?
Thanks again,
Eric
- Help with recursive destructive function, Eric Abrahamsen, 2018/05/04
- Re: Help with recursive destructive function, Stefan Monnier, 2018/05/04
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/06
- Re: Help with recursive destructive function, Michael Heerdegen, 2018/05/06
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/06
- Re: Help with recursive destructive function, Clément Pit-Claudel, 2018/05/07
- Re: Help with recursive destructive function, Michael Heerdegen, 2018/05/07
- Re: Help with recursive destructive function, Stefan Monnier, 2018/05/07
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/07
- Re: Help with recursive destructive function, Michael Heerdegen, 2018/05/08