* bug#36772: feature request: checked variant of "substitute*"
@ 2019-07-23 12:49 Robert Vollmert
2019-07-23 13:35 ` Ricardo Wurmus
0 siblings, 1 reply; 4+ messages in thread
From: Robert Vollmert @ 2019-07-23 12:49 UTC (permalink / raw)
To: 36772
I think it would be great to have the following variant of substitute*:
(substitute*-once filename (pattern vars) body)
which acts like the usual substitute-*, except it also asserts that the
substitution applies to exactly one line in the file, causing a build
failure otherwise.
In the cases where this is sufficient (I believe most), it would make
substitution work quite a bit more reliably, making it both easier to
debug substitution when first packaging, and noticing more easily when
they need to be adapted on upgrades.
(It would be possible to make the signature a bit more flexible and to
allow multiple files or patterns as in substitute*, but that would
make the meaning of “applies exactly once” a bit unclear, so I’d prefer
to not do that. Similarly, I find it cleaner to potentially call
substitute*-once several times in a row with different substitutions to
make the ordering of effects explicit.)
(I’d be happy to supply a patch myself eventually, but the syntax rule
business is a bit out of reach at this point.)
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#36772: feature request: checked variant of "substitute*"
2019-07-23 12:49 bug#36772: feature request: checked variant of "substitute*" Robert Vollmert
@ 2019-07-23 13:35 ` Ricardo Wurmus
2019-07-23 13:41 ` Robert Vollmert
2019-07-25 17:40 ` Ludovic Courtès
0 siblings, 2 replies; 4+ messages in thread
From: Ricardo Wurmus @ 2019-07-23 13:35 UTC (permalink / raw)
To: Robert Vollmert; +Cc: 36772
Hi Robert,
> I think it would be great to have the following variant of substitute*:
>
> (substitute*-once filename (pattern vars) body)
>
> which acts like the usual substitute-*, except it also asserts that the
> substitution applies to exactly one line in the file, causing a build
> failure otherwise.
I agree that the effect of substitute* should be checked. I think
substitute* should fail when one of its clauses failed to match
anything.
Each clause could also accept an optional argument to make them only
match one location. We wouldn’t have to duplicate the macro for that
and it’s a simple extension to failing on zero matches.
What do you think?
--
Ricardo
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#36772: feature request: checked variant of "substitute*"
2019-07-23 13:35 ` Ricardo Wurmus
@ 2019-07-23 13:41 ` Robert Vollmert
2019-07-25 17:40 ` Ludovic Courtès
1 sibling, 0 replies; 4+ messages in thread
From: Robert Vollmert @ 2019-07-23 13:41 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: 36772
> On 23. Jul 2019, at 15:35, Ricardo Wurmus <rekado@elephly.net> wrote:
>
>
> Hi Robert,
>
>> I think it would be great to have the following variant of substitute*:
>>
>> (substitute*-once filename (pattern vars) body)
>>
>> which acts like the usual substitute-*, except it also asserts that the
>> substitution applies to exactly one line in the file, causing a build
>> failure otherwise.
>
> I agree that the effect of substitute* should be checked. I think
> substitute* should fail when one of its clauses failed to match
> anything.
>
> Each clause could also accept an optional argument to make them only
> match one location. We wouldn’t have to duplicate the macro for that
> and it’s a simple extension to failing on zero matches.
>
> What do you think?
That sounds like a good improvement, too. I think the important part is
ensuring the substitution matches at all, maybe we could leave out the
“at most once” part. (I doubt it would be used a lot if it’s not the default.)
Cheers
Robert
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#36772: feature request: checked variant of "substitute*"
2019-07-23 13:35 ` Ricardo Wurmus
2019-07-23 13:41 ` Robert Vollmert
@ 2019-07-25 17:40 ` Ludovic Courtès
1 sibling, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2019-07-25 17:40 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: 36772, Robert Vollmert
Hi,
Ricardo Wurmus <rekado@elephly.net> skribis:
>> I think it would be great to have the following variant of substitute*:
>>
>> (substitute*-once filename (pattern vars) body)
>>
>> which acts like the usual substitute-*, except it also asserts that the
>> substitution applies to exactly one line in the file, causing a build
>> failure otherwise.
>
> I agree that the effect of substitute* should be checked. I think
> substitute* should fail when one of its clauses failed to match
> anything.
>
> Each clause could also accept an optional argument to make them only
> match one location. We wouldn’t have to duplicate the macro for that
> and it’s a simple extension to failing on zero matches.
>
> What do you think?
That’d be a useful extension.
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-25 17:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-23 12:49 bug#36772: feature request: checked variant of "substitute*" Robert Vollmert
2019-07-23 13:35 ` Ricardo Wurmus
2019-07-23 13:41 ` Robert Vollmert
2019-07-25 17:40 ` Ludovic Courtès
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.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).