Re: defines varname { [values]... } prog...

From: Emanuele Torre <torreemanuele6_at_gmail.com>
Date: Fri, 24 May 2024 14:17:23 +0200

On Fri, May 24, 2024 at 08:57:27AM +0000, Laurent Bercot wrote:
> Does that solve your issue?
>
> --
> Laurent

Sorry, but your suggestions are completely useless.

>
> > To prevent literal "$y"s or "${y}"s in the value of VARA ($x) from
> > expanding, you must replace the second expansion command with a
> > multisubstitute, and give the variable that was declared before
> > multisubsitete another name using define
>
> I would argue the opposite, i.e. that parallel substitution
> (using multisubstitute) should be the norm, and that serial substitution
> should only happen when you know you need the result of an early
> substitutions in a later one.
>
> Which means I would rewrite your example as:
>
> multisubstitute
> {
> importas -i x VARA
> importas -i y VARB
> }
> cmdA argA $x
> cmdB argB $x $y
>
> and there would be no problem with literal $y being replaced in the
> expansion of $x. This is valid with elglob too.
>

The original code was

    importas -i x VARA
    cmdA argA $x
    multisubstitute {
        define newx $x
        importas -i y VARB
    }
    cmdB argB $newx $y

VARB can be set by cmdA, which is a command that needs VARA to be
expanded to run; which is a *extremely* common thing even with the
standard execline utitlities.
E.g. wait, pipeline, ...

> Your example with backtick doesn't work because backtick is not a
> substitution command, but let's assume you wanted "importas foo BAR"

I am sorry, yes.

    elglob cfiles *.c
    foreground { cmdA argA $cfiles }
    backtick FOO { bar }
    multisubstitute {
        defines newcfiles { $cfiles }
        importas -i foo FOO
    }
    cmdB argB $foo $cfiles

> instead; and your use of "cmdA argA $cfiles" followed by the rest
> of the script is sketchy, because if cmdA takes a variable number of
> arguments, it would also take the whole rest of the script, so let's
> put it in a foreground block.
>
> So you would have something like:
>
> multisubstitute
> {
> elglob cfiles *.c
> importas -i foo BAR
> }
> foreground { cmdA argA $cfiles }
> cmbB argB $foo $cfiles
>
> and there will be no problem in the expansion of $foo either.
>

But that is wrong; you are assuming that cmdA does not create/deletes
files; I don't think it is that unreasonable to want to use the same
list of files for two commands instead of expanding *.c twice that
results in different values.

o/
 emanuele6
Received on Fri May 24 2024 - 14:17:23 CEST

This archive was generated by hypermail 2.4.0 : Fri May 24 2024 - 14:17:54 CEST