all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: emacs-devel@gnu.org
Subject: Re: Help with recursive destructive function
Date: Tue, 15 May 2018 01:16:45 +0200	[thread overview]
Message-ID: <87y3glomjm.fsf@web.de> (raw)
In-Reply-To: <87bmdixji9.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Mon, 14 May 2018 09:57:34 -0700")

Eric Abrahamsen <eric@ericabrahamsen.net> 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.



  reply	other threads:[~2018-05-14 23:16 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-05  1:04 Help with recursive destructive function Eric Abrahamsen
2018-05-05  1:18 ` Stefan Monnier
2018-05-05  1:37   ` Michael Heerdegen
2018-05-05 15:41     ` Michael Heerdegen
2018-05-06 17:29       ` Eric Abrahamsen
2018-05-06 19:29         ` Michael Heerdegen
2018-05-06 19:34           ` Eric Abrahamsen
2018-05-06 18:27       ` Eric Abrahamsen
2018-05-07  2:01         ` Michael Heerdegen
2018-05-07  3:01           ` Eric Abrahamsen
2018-05-07  4:16             ` Clément Pit-Claudel
2018-05-07 14:14               ` Michael Heerdegen
2018-05-07 16:26               ` Stefan Monnier
2018-05-07 16:52                 ` Eric Abrahamsen
2018-05-08 13:15                   ` Michael Heerdegen
2018-05-08 18:42                     ` Eric Abrahamsen
2018-05-08 19:03                       ` Clément Pit-Claudel
2018-05-08 19:41                         ` Eric Abrahamsen
2018-05-10  1:52                       ` Michael Heerdegen
2018-05-10 17:08                         ` Michael Heerdegen
2018-05-11  2:12                           ` Eric Abrahamsen
2018-05-14 14:27                             ` Michael Heerdegen
2018-05-14 16:57                               ` Eric Abrahamsen
2018-05-14 23:16                                 ` Michael Heerdegen [this message]
2018-05-15  0:28                                   ` Eric Abrahamsen
2018-07-28 20:52                                   ` Eric Abrahamsen
2018-07-28 23:46                                     ` Michael Heerdegen
2018-07-28 23:59                                       ` Eric Abrahamsen
2018-07-29  0:09                                         ` Michael Heerdegen
2018-06-04 22:28                               ` Eric Abrahamsen
2018-06-05  0:23                                 ` Michael Heerdegen
2018-06-06 21:04                                   ` Eric Abrahamsen
2018-06-06 21:58                                     ` Michael Heerdegen
2018-06-06 22:10                                       ` Eric Abrahamsen
2018-06-06 23:10                                         ` Eric Abrahamsen
2018-06-06 23:30                                           ` Michael Heerdegen
2018-06-07  0:49                                             ` Eric Abrahamsen
2018-06-07  1:13                                               ` Michael Heerdegen
2018-06-06 23:18                                         ` Michael Heerdegen
2018-06-07 13:59                                     ` Stefan Monnier
2018-06-07 16:51                                       ` Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y3glomjm.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=emacs-devel@gnu.org \
    --cc=eric@ericabrahamsen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.