[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with recursive destructive function
From: |
Michael Heerdegen |
Subject: |
Re: Help with recursive destructive function |
Date: |
Mon, 07 May 2018 04:01:03 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Eric Abrahamsen <address@hidden> writes:
> Oh hang on, this doesn't work for all cases: the "by #'cdr" prevents
> it from hitting the cdr of cons cells:
>
> (let ((tree '("c" (2 ("d" . 3)) (4 . "e") "f")))
> (iter-do (_ (iter-tree-example tree)))
> tree)
>
> --> ("C" (2 ("D" . 3)) (4 . "e") "F")
Not only that (it's easy to fix), but I also realized that this approach
doesn't circumvent the recursion issue. But if your data is not
extremely deeply nested, recursion should not be such a problem.
> The best I've been able to come up with is:
>
> (defun useless (val)
> (while (consp val)
> (let ((head (car val)))
> (cond ((stringp head)
> (setcar val (upcase head)))
> ((listp head)
> (useless head)))
> (when (stringp (cdr val))
> (setcdr val (upcase (cdr val))))
> (setq val (cdr val)))))
>
> Recurses on car, and only repeats the test twice. I'd love to know if
> that could be simplified...
Looks ok to me in principle.
Michael.
- 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 <=
- 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
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/08
- Re: Help with recursive destructive function, Clément Pit-Claudel, 2018/05/08
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/08
- Re: Help with recursive destructive function, Michael Heerdegen, 2018/05/09