unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thievol@posteo.net>
To: Juri Linkov <juri@linkov.net>
Cc: Lars Ingebrigtsen <larsi@gnus.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel@gnu.org
Subject: Re: Improve `replace-regexp-in-string' ergonomics?
Date: Wed, 13 Oct 2021 08:41:10 +0000	[thread overview]
Message-ID: <87y26xe1ni.fsf@posteo.net> (raw)
In-Reply-To: <8735p5z79i.fsf@mail.linkov.net>

[-- Attachment #1: Type: text/plain, Size: 1555 bytes --]


Juri Linkov <juri@linkov.net> writes:

>>> What does the following return?
>>>
>>>     (let ((bar "bar"))
>>>       (helm-aand bar
>>>                  (replace-regexp-in-string "b" "f" it)
>>>                  (replace-regexp-in-string "f" "o" it)))
>>>
>>> If it returns "oar" then it applies replacements sequentially,
>>> and we have no problem with such implementations.
>>
>> Yes, it does, thought you wanted something easy to read (and write), it
>> was the initial question isn't it?
>
> General-purpose threading like you proposed is a nice feature.
> But is supports only sequential replacements.
>
>>> But we need an alternative version that performs simultaneous
>>> replacements and returns "far".
>>
>> So I don't understand what you want to achieve.
>
> Most of replacements are intended to be simultaneous.
> But in practice most of simultaneous replacements
> could be performed using sequential replacement
> because often the result of every replacement step
> doesn't contain matches for the next replacement step.
>
> But sometimes simultaneous replacement is required.
> For example,
>
>     (let ((bar "<&"))
>       (helm-aand bar
>                  (replace-regexp-in-string "<" "&lt;" it)
>                  (replace-regexp-in-string "&" "&amp;" it)))
>
> will do the wrong thing (and will return "&amp;lt;&amp;" instead of the
> intended "&lt;&amp;") because these replacements should be performed
> simultaneously.

I see what you mean now, thanks for explanations. 

-- 
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

      reply	other threads:[~2021-10-13  8:41 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  4:36 Improve `replace-regexp-in-string' ergonomics? Lars Ingebrigtsen
2021-09-22  5:22 ` Yuri Khan
2021-09-22  6:36   ` Lars Ingebrigtsen
2021-09-22  7:47   ` Thierry Volpiatto
2021-09-22  5:24 ` Po Lu
2021-09-22  6:37   ` Lars Ingebrigtsen
2021-09-22 10:56     ` Po Lu
2021-09-22 20:08       ` Lars Ingebrigtsen
2021-09-23  0:11         ` Po Lu
2021-09-22  7:33 ` Adam Porter
2021-09-22  8:09   ` Lars Ingebrigtsen
2021-09-22  7:51 ` Andreas Schwab
2021-09-22  8:14 ` Augusto Stoffel
2021-09-22  8:21   ` Adam Porter
2021-09-22 18:01     ` Stefan Monnier
2021-09-22 18:24       ` Basil L. Contovounesios
2021-09-22 22:56       ` Adam Porter
2021-09-22 23:53         ` Eric Abrahamsen
2021-09-22 20:06   ` Lars Ingebrigtsen
2021-09-22 10:59 ` Dmitry Gutov
2021-09-22 20:18   ` Lars Ingebrigtsen
2021-09-22 22:23     ` Dmitry Gutov
2021-09-22 23:24       ` [External] : " Drew Adams
2021-09-22 18:14 ` Stefan Monnier
2021-09-22 19:30   ` Mattias Engdegård
2021-09-22 20:22   ` Lars Ingebrigtsen
2021-09-22 20:29     ` Lars Ingebrigtsen
2021-09-23  2:15     ` Stefan Monnier
2021-10-05 16:18 ` Juri Linkov
2021-10-12  6:53   ` Juri Linkov
2021-10-12 12:10     ` Lars Ingebrigtsen
2021-10-12 12:34       ` Stefan Monnier
2021-10-12 12:41         ` Lars Ingebrigtsen
2021-10-12 13:18           ` Lars Ingebrigtsen
2021-10-12 13:32             ` Mattias Engdegård
2021-10-12 15:48             ` Stefan Monnier
2021-10-12 13:33           ` Thierry Volpiatto
2021-10-12 19:16             ` Juri Linkov
2021-10-12 20:44               ` Thierry Volpiatto
2021-10-13  7:57                 ` Juri Linkov
2021-10-13  8:41                   ` Thierry Volpiatto [this message]

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y26xe1ni.fsf@posteo.net \
    --to=thievol@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).