emacs-devel
[Top][All Lists]
Advanced

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

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


From: Thierry Volpiatto
Subject: Re: Improve `replace-regexp-in-string' ergonomics?
Date: Wed, 13 Oct 2021 08:41:10 +0000

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: signature.asc
Description: PGP signature


reply via email to

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