From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-devel@gnu.org
Subject: Re: Help with recursive destructive function
Date: Mon, 07 May 2018 09:52:49 -0700 [thread overview]
Message-ID: <877eof1k7y.fsf@ericabrahamsen.net> (raw)
In-Reply-To: jwvpo27tpd0.fsf-monnier+gmane.emacs.devel@gnu.org
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (defun deep-edit (f data)
>> (let ((cur (list #'car #'setcar data))
>> (stack (list (list #'cdr #'setcdr data))))
>> (while cur
>> (let* ((getter (car cur))
>> (setter (cadr cur))
>> (tree (caddr cur))
>> (subtree (funcall getter tree)))
>> (funcall setter tree (funcall f subtree))
>> (cond
>> ((consp subtree)
>> (push (list #'cdr #'setcdr subtree) stack)
>> (setq cur (list #'car #'setcar subtree)))
>> (t (setq cur (pop stack))))))))
>
> BTW, a "cleaner" (tho less efficient) way uses gv-ref:
>
> (defun deep-edit (f data)
> (let ((cur (gv-ref (car data)))
> (stack (list (gv-ref (cdr data)))))
> (while (or cur stack)
> ;; Probably should use (cl-callf f (gv-deref cell)).
> (pcase (setf (gv-deref cur) (funcall f (gv-deref cell)))
> ((and (pred consp) subtree)
> (push (gv-ref (cdr subtree)) stack)
> (setq cur (gv-ref (car subtree))))
> (t (setq cur (pop stack)))))))
>
> tho the above has a bug when cur is nil, so it won't work as is.
All this went very rapidly over my head, but I guess that's what I was
hoping for! I'll wait and see if you all work this through any further,
then play around with the results, and update bug #29541 with a new patch.
Thanks!
Eric
next prev parent reply other threads:[~2018-05-07 16:52 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 [this message]
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
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=877eof1k7y.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=emacs-devel@gnu.org \
/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.