From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: Help with recursive destructive function Date: Tue, 15 May 2018 01:16:45 +0200 Message-ID: <87y3glomjm.fsf@web.de> References: <87efiqzzd2.fsf@ericabrahamsen.net> <87bmdu3mtf.fsf@web.de> <87zi1e9kju.fsf@web.de> <87o9hs3aht.fsf@ericabrahamsen.net> <87bmds9qcg.fsf@web.de> <87k1sg185t.fsf@ericabrahamsen.net> <044bdbf1-39a2-0e71-ec79-3d375d9109c8@gmail.com> <877eof1k7y.fsf@ericabrahamsen.net> <87wowe2sql.fsf@web.de> <877eoe2dma.fsf@ericabrahamsen.net> <87tvrgqnug.fsf@web.de> <87vabvbfrj.fsf@web.de> <87d0y30wkn.fsf@ericabrahamsen.net> <878t8mtiqz.fsf@web.de> <87bmdixji9.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1526339742 28619 195.159.176.226 (14 May 2018 23:15:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 14 May 2018 23:15:42 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eric Abrahamsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 15 01:15:37 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fIMgr-0007M2-DW for ged-emacs-devel@m.gmane.org; Tue, 15 May 2018 01:15:37 +0200 Original-Received: from localhost ([::1]:53321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIMiy-0002xn-8d for ged-emacs-devel@m.gmane.org; Mon, 14 May 2018 19:17:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIMiD-0002wP-9M for emacs-devel@gnu.org; Mon, 14 May 2018 19:17:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIMiA-0001kp-3J for emacs-devel@gnu.org; Mon, 14 May 2018 19:17:01 -0400 Original-Received: from mout.web.de ([217.72.192.78]:48321) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIMi9-0001hE-Py for emacs-devel@gnu.org; Mon, 14 May 2018 19:16:58 -0400 Original-Received: from drachen.dragon ([188.110.196.170]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LdVza-1eZzY506Ik-00imgd; Tue, 15 May 2018 01:16:47 +0200 In-Reply-To: <87bmdixji9.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Mon, 14 May 2018 09:57:34 -0700") X-Provags-ID: V03:K1:qujwkZ0WkIFCUaGXW+kcN+Qc6MxNIArASfjiiL8Hu2YEOfl2LtY rGlRhscnxE3QQMIcGZ0j+uJVxghJWNrnbl5KWo/bFgqqYlRDzkxaHch69XpozY/8fRm4Lsh hfHRmqeK1UTphqNm4legW/GhO/84luQUBBHXizP+gs2Ls1jRNfs0hhj7YdUI6cQ5lhlHoLw BIEs9fjc0MK2sQRwHQGww== X-UI-Out-Filterresults: notjunk:1;V01:K0:CVmD0oyHSBQ=:U5RlsX6ZQObPQUhPDL/VGi iViyuNniuQQQ7SY77hhCcS1fxr/7cNQFeJ8eRyZHO6D0+tatYG2k6nceAR8PDK93vwz/A35yv A6SCBg2W2soM+2Fx6+d7GPtnutVHhQSz9qhWebYc7lDqf6VYc37bDPaEqAql2+sEGj7FoHURi jiotLSVJHOU3jszLG8CTngTYpDMwRO7f5wZbrv3nAG4Hw/NdsAdzpiK8Me7WSorxyejWd9ZJg +8d6HIWQLbnQ6ejHYKj/4DmkRPdDOX8YsNVlL1/C4+/+AbPglXN6z0HIKZc83iuzO/bc5HSdv 2pRiZY8ct6alZ9W0blft/tT+vRhwd2NcqpIsF1Ypjngt/SPHUA6ieukBVfbxUsseRll/4zJtx lXpPId+WSXHZqJNGNh77fjEm+2EqcuhhJLii3CFGLzQjF7CNMP7h02hxVetKr7nAveoktlUdg BQBfIhhVBm134gal2RXTVrQ0BLg0rH+4idRiWwacunwFZFO6+4ueOubgY/11e5BB94SBQyXij +Ud79UNDS5rIuwPXr5QVuwqoyJZyf08RoguD8E9vlklWb1zBGQG5lzoBm/AtvztEzOd5yR3Md uIrMQ1fd7ELQ6vo7//1WBw39nGvFBYRyrrdypV+slb1Fl2w22XtcSfmJYdZTeU99OpIcJrntJ IBJMSGt8a62X2BhzrYrKyuH9CWWa//fx5H4RyhDbvtmVO7GASbMlzf6hi0yHOBQBz6J2buYq5 O6UgZlvKLzGpqFMxt52XaUFQnTD1d+JAOg94/F68tDJotBj76JJcYRnQHsEMOgIjwgPzbiom X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.78 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:225294 Archived-At: Eric Abrahamsen 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.