From: Michael Heerdegen <michael_heerdegen@web.de>
To: Chunyang Xu <mail@xuchunyang.me>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Can el-search-query-replace replace mapcar with --map ?
Date: Fri, 22 Dec 2017 18:17:57 +0100 [thread overview]
Message-ID: <87a7yahebe.fsf@web.de> (raw)
In-Reply-To: <m21sjn6l6k.fsf@xuchunyang.me> (Chunyang Xu's message of "Fri, 22 Dec 2017 19:45:07 +0800")
Chunyang Xu <mail@xuchunyang.me> 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.
next prev parent reply other threads:[~2017-12-22 17:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-22 11:45 Can el-search-query-replace replace mapcar with --map ? Chunyang Xu
2017-12-22 17:17 ` Michael Heerdegen [this message]
2017-12-23 6:17 ` Chunyang Xu
2017-12-23 14:03 ` Michael Heerdegen
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=87a7yahebe.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=help-gnu-emacs@gnu.org \
--cc=mail@xuchunyang.me \
/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.