On Tuesday, May 26th, 2026 at 2:38 PM, Noé Lopez via "Development of GNU Guix 
and the GNU System distribution." <[email protected]> wrote:

> Maxim Cournoyer <[email protected]> writes:
> 
> > Hi again,
> >
> > Noé Lopez via "Development of GNU Guix and the GNU System distribution."
> > <[email protected]> writes:
> >
> > [...]
> >
> >> `substitute-file`
> >>         Substitutes one or multiple files, all regexes must
> >>         match for all files. Takes optional argument to make each regex 
> >> only
> >>         have to match once.
> >>
> >> There is no option to have a regex that never matches.
> >
> > I forgot to mention; if we go with a brand new API, we could use a
> > procedure instead of syntax for substitute-file; it ends up calling to a
> > procedure anyway, but having it syntax means that it's less flexible
> > (IIRC, it's bad form to have dynamically computed patterns with
> > string-append or format for example -- I forgot why that was, perhaps
> > because of its syntax nature?)
> >
> > Was there a reason to have substitute* as syntax rather than as a plain
> > procedure?
> >
> 
> I don’t know, it was probably more fancy. But I also agree that its
> overdone and makes the implementation needlessly complicated.

I don't know the design decisions around substitute* being syntax, but isn't it 
as syntax necessary for supporting capture variables for the whole match and 
any submatches? For example, the Guix reference manual includes the following 
example with capturing in the entry for the substitute* macro:

  (substitute* file
    (("hello")
     "good morning\n")
    (("foo([a-z]+)bar(.*)$" all letters end)
     (string-append "baz" letters end)))

>From what I know of Scheme, the above example cannot be achieved with 
>procedures, as everything after the file argument would fail to evaluate as-is 
>(e.g. it would want to look up the variables "all", "letters", and "end" 
>instead of binding them, and it would try to invoke the string "hello" as a 
>function, etc). Making a substitute*-alike procedure would require a different 
>structure for its usage, such as receiving a function for the replacement 
>string that can be invoked with the matched (sub-)expressions as positional 
>arguments.

Cheers,
Kaelyn

Reply via email to