[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: |
Tue, 15 May 2018 01:16:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Eric Abrahamsen <address@hidden> writes:
> For backwards compatibility, we need to be able to handle lists that are
> quoted, or that start with the symbol `list'. This will sound familiar
> to you... In the non-destructive version, it was easy enough just to
> return (cdr thing) instead of thing.
What will this code do when the saved list was really quoted, or was a
list with the symbol list as first element? Wouldn't the backward
compatible version cause errors?
> In the destructive version, this means that `handle-refs' would need to
> first edit and *then* traverse the cons, which is not what it's set up
> to do, obviously. I could probably cheat and move the backward
> compatibility into some other part of `deep-edit' itself, but I was
> trying to avoid that because that function could be useful elsewhere as
> part of the general library.
My implementation so far doesn't perfectly fit that case (as you
noticed).
Do you expect something occurring like '1 or (list) - i.e. cases where
the remaining thing is an atom (like 1 and nil above)?
If not, I would just tweak `handle-refs' so that it calls the modify
function _and_ additionally pushes the replacement to the stack when
some condition is met. You could make it so that `edit-func' returns a
special value for this case, like in
#+begin_src emacs-lisp
(defun edit-func (proposed-value)
(cond ((and (consp proposed-value)
(eq (car proposed-value) 'list))
(list t #'cdr))
((and (consp proposed-value)
(eq (car proposed-value) 'quote))
(list t #'cadr))
((stringp proposed-value)
#'upcase)
(t nil)))
#+end_src
where (list t FUN) would mean that we want to modify the value with FUN
and additionally push the resulting (remaining) tree to the stack. Not
much magic here...
Michael.
- Re: Help with recursive destructive function, (continued)
- 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
- Re: Help with recursive destructive function, Michael Heerdegen, 2018/05/10
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/10
- Re: Help with recursive destructive function, Michael Heerdegen, 2018/05/14
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/14
- Re: Help with recursive destructive function,
Michael Heerdegen <=
- Re: Help with recursive destructive function, Eric Abrahamsen, 2018/05/14