[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Improve `replace-regexp-in-string' ergonomics?

From: Juri Linkov
Subject: Re: Improve `replace-regexp-in-string' ergonomics?
Date: Wed, 13 Oct 2021 10:57:45 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]