[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 "<" "<" it)
> (replace-regexp-in-string "&" "&" it)))
>
> will do the wrong thing (and will return "&lt;&" instead of the
> intended "<&") because these replacements should be performed
> simultaneously.
I see what you mean now, thanks for explanations.
--
Thierry
signature.asc
Description: PGP signature
- Re: Improve `replace-regexp-in-string' ergonomics?, (continued)
- Re: Improve `replace-regexp-in-string' ergonomics?, Lars Ingebrigtsen, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Stefan Monnier, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Lars Ingebrigtsen, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Lars Ingebrigtsen, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Mattias EngdegÄrd, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Stefan Monnier, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Thierry Volpiatto, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Juri Linkov, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Thierry Volpiatto, 2021/10/12
- Re: Improve `replace-regexp-in-string' ergonomics?, Juri Linkov, 2021/10/13
- Re: Improve `replace-regexp-in-string' ergonomics?,
Thierry Volpiatto <=