From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: Can el-search-query-replace replace mapcar with --map ? Date: Fri, 22 Dec 2017 18:17:57 +0100 Message-ID: <87a7yahebe.fsf@web.de> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1513963016 14024 195.159.176.226 (22 Dec 2017 17:16:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 22 Dec 2017 17:16:56 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Chunyang Xu Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 22 18:16:52 2017 Return-path: Envelope-to: geh-help-gnu-emacs@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 1eSQwC-0003Cn-1M for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Dec 2017 18:16:48 +0100 Original-Received: from localhost ([::1]:58909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSQyA-0007fa-7m for geh-help-gnu-emacs@m.gmane.org; Fri, 22 Dec 2017 12:18:50 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSQxU-0007e8-8l for help-gnu-emacs@gnu.org; Fri, 22 Dec 2017 12:18:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSQxO-0007rH-LL for help-gnu-emacs@gnu.org; Fri, 22 Dec 2017 12:18:08 -0500 Original-Received: from mout.web.de ([212.227.15.3]:58438) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eSQxO-0007pG-Bu for help-gnu-emacs@gnu.org; Fri, 22 Dec 2017 12:18:02 -0500 Original-Received: from drachen.dragon ([88.74.120.211]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MXpaR-1eW1Jp1a3r-00WqJJ; Fri, 22 Dec 2017 18:17:58 +0100 In-Reply-To: (Chunyang Xu's message of "Fri, 22 Dec 2017 19:45:07 +0800") X-Provags-ID: V03:K0:28/o4syOwT994uthlcCJnIDUds0Q3TTS1tEpvvVWO8cfKigNbp1 sbySEvo6L2P6lV351AsoheLb/dbSNzoXYLlHe4XwvqGXoB2r0WE2RttCrrEU8FnDFIH5haJ Y9+74hwAhMScN/lCretkwuoWgOIFDsC2FiyYWkF6ZiXYDhxP11XDKb3ZyD+5YY8ugXM2nfo eDtKIx3d9TQcEe8qcWHcQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:O5ZZtk+R/1c=:6sBiw5Ojrvbm452WDzb78B Mvyml4bCbSWPUk2z4S5p0s7DTB1sEKssncrq6MAyCIzQ6Wj8mq1aStTGWfQl43GmrwFZ0oCAm aolm5T/h1yzP4dLrbf+U1eNFOpulA7HybS064SHFH5cuBcCbW4LCza5mRtMABIO/oCKlAxSpq 0Qx0xRqYO4Qb+ek4GGtexZwJBZgz1zRRJ1iDKPCj9Bz983j/4FV392Hbq6eUgBbjRjzoqsAvI ezQV6L2LvwmQyeru9c6l40pkfEN7bGQw5baxuh2ez5dPDbyEwL97TSFitKv3s2V3WGOw/Ze1x p1MpnzvooY4qtS+Tg6Q4kMgtS32jsENdw8jgAMSgEygRJZGI2JYaPds685xzvNLaDT0kWi018 s4UeQh9Y25mM8DLs6rWsb4+AbMo/nWkV7RJ+0nbj/Ne7pbxDqXXn7nLFaA9PWaJ8zaQLGunkU EQLZpDChPMS84JSkI6rNwLXRmnXvoI3Ln8VQwtq7rWP93zLz2cPlTw+Wohd4gDgS5YaFk7Pvs bjiI8xPCTRLCEgyPKeYQDvZlOl2xKhTYA6Sjhdol9szGgZaXneY3WOj9Z465eUyKpCOjnbjEz 3WXVWUFXtclZwvTe137A2H1KJbv4I3MsYv7wKtHFsFWSKW3gaAokrtkBpPWA+7e8Xfobl3OB5 KwqivGmMjEyCLdM6GBcv+BQrTMwmRzdSTYt3CvTTMVENSv0eq5Fe2GJMay0y0Tw6HqklzpNiE mhQDLky+334swAOpNt7YnLaJqNznvjXozQ/1soM8zGwMEVYiTsW7+U2HyNPaETWELmJtaCwy X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115430 Archived-At: Chunyang Xu writes: > It gives me: > > (--map > (* x x) > '(1 2 3)) which is expected, of course. The transformation you want is not trivial, and there are some problematic cases when it gets complicated - e.g. when the mapped lambda uses in its body a local variable with the same name as the argument variable, like in #+begin_src emacs-lisp (lambda (x) (let ((x (1+ x))) (* x x))) #+end_src But that should be corner cases in practice. I would define a helper function to perform the renaming of the lambda argument into "it" - something like #+begin_src emacs-lisp (defun transform-lambda-form-for---map (lambda-form) (pcase-let ((`(lambda (,var) . ,body) lambda-form)) (macroexpand-1 `(cl-symbol-macrolet ((,var it)) ,@body)))) #+end_src and then el-search-query-replace with the rule #+begin_src emacs-lisp `(mapcar ,lambda-form ,list) -> `(--map ,(transform-lambda-form-for---map lambda-form) ,list) #+end_src Does that work ok for you? Regards, Michael.