emacs-devel
[Top][All Lists]
Advanced

[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: Mon, 14 May 2018 09:57:34 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Michael Heerdegen <address@hidden> writes:

> Eric Abrahamsen <address@hidden> writes:
>
>> This is great, and I really like the use of gv -- morally it seems like
>> the right tool.
>
> Didn't profile speed, however - hope it's good enough.

I'm trying to break the changes into discrete steps, and benchmark each
step, so hopefully we'll know.

>> I will have time this weekend to apply all this to eieio-persistent.
>
> Where can I have a look at your work?

Nowhere yet -- I got partway through this, and ran up against a dumb
problem maybe you can help me with.

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.

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.

Here's what the problem actually looks like:

#+BEGIN_SRC elisp
  (defun edit-func (proposed-value)
    (cond ((and (consp proposed-value)
                (eq (car proposed-value) 'list))
           #'cdr)
          ((and (consp proposed-value)
                (eq (car proposed-value) 'quote))
           #'cadr)
          ((stringp proposed-value)
           #'upcase)
          (t nil)))

  (let ((tree '("b" '((first ("one" "two" "three"))
                      (second ("four" "five" "six")))
                "c" (list "seven" "eight" "nine"))))
    (deep-edit #'edit-func
               (lambda (thing) (consp thing))
               tree)
    tree)
#+END_SRC

Do you have any good ideas about this?

Thanks again,
Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]