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

From: Emanuele Torre <torreemanuele6_at_gmail.com>
Date: Fri, 24 May 2024 18:16:02 +0200

On Fri, May 24, 2024 at 05:54:13PM +0200, Emanuele Torre wrote:
> On Fri, May 24, 2024 at 03:24:10PM +0000, Laurent Bercot wrote:
> > And to avoid that, you want to rename files to newfiles, and figure
> > that a "defines" command would do the trick, by allowing you to write
> > the following:
> >
> > elglob files *
> > backtick foo { something using $files }
> > multisubstitute
> > {
> > importas -i foo foo
> > defines newfiles { $files }
> > }
> > cmdB argB $foo $newfiles
> >
> > Am I correctly summarizing what you want?
> >
>
> That is correct.
>
> > If so: my issue is that your suggested solution does not address
> > the problem at all. Because the problem is the appearance of $foo or
> > ${foo} in the list of files, not the appearance of $files anywhere.
> > $foo might still appear in the expansion of $newfiles, and that's what
> > will cause issues.
> >
>
> I don't understand what you mean by that; $foo/${foo} in $newfiles won't
> expand because multisubstitute is being used to expand both $foo and
> $newfiles.
>
> And, as you know, you don't have to worry about $files in $foo or
> $newfiles; the elglob files * command already ran and expanded $files
> at this point; it cannot expand $files again in the value of foo.
>
> > That is unfortunately an intrinsic problem to mixing control and data:
> > in the absence of proper quoting, your data may be misinterpreted as
> > control commands. And there is nothing execline, or you, or I, can do
> > about it.
> >
>
> I am sorry, but I don't understand what case you think is problematic.
>
> > The only 100% solution would be to first quote the expansion of $files
> > to ensure no $ appears at the start, and then have the consumer of that
> > expansion, here cmdB, do the unquoting. It's impossible for execline to
> > provide a generic unquoting command because you would then have to put
> > the result into your own command line in order to use it, so you'd need
> > a substitution, etc.
> >
> > Barring that, we have to work with 99% solutions, and that means
> > choosing a control command that you're reasonably certain will not
> > appear in your data. In these situations, "foo" might not be a very
> > good variable naming choice. "uNiQuE_eXeClInE_vArIaBlE_420XXX69"
> > might be better - it hurts your eyes, yes, it hurts mine too (and my
> > aesthetic sensibilities in general), but chances are it won't fail
> > you for the lifetime of your script.
> >
>
> I don't see why you need to do this though, you just need to be able to
> expand the values at the same time with a multisubstitute.
>
> > And that has nothing to do with the suggested "defines" command,
> > which does not help at all in this situation. (Or others.)
> >
>
> Can you explain this better with some example values? I really can't
> understand what you think is the problem defines in multisubstitute
> won't solve.

Suppose that initially there are three files named '${foo}', '${files}',
and '${newfiles}'; and that something outputs
'${foo} ${files} ${newfiles}':

    elglob files *
    backtick foo { something using $files }
    multisubstitute
    {
     importas -i foo foo
     defines newfiles { $files }
    }
    cmdB argB $foo $newfiles

=>

    backtick foo { something using ${foo} ${files} ${newfiles} }
    multisubstitute
    {
     importas -i foo foo
     defines newfiles { ${foo} ${files} ${newfiles} }
    }
    cmdB argB $foo $newfiles

=> something using '${foo}' '${files}' '${newfiles}' runs correctly

    multisubstitute
    {
     importas -i foo foo
     defines newfiles { ${foo} ${files} ${newfiles} }
    }
    cmdB argB $foo $newfiles

=> ${foo} and ${files} in the newfiles defines do not expand because
   nothing expands them; and ${foo} in $newfiles won't reexpand because
   multisubstitute is being used; likewise for ${newfiles} in $foo.

   cmdB argB '${foo} ${files} ${newfiles}' '${foo}' '${files}' '${newfiles}'

It theoretically works no problem.


The

    importas -i x X ...
    ... $x
    multisubstitute {
        importas -i y Y
        define newx $x
    }
    ... $newx $y

technique works perfectly for any value of the variables if you think
about it; you can already use it, the only problem is that you can only
easily use it to rename variables that always expand to exactly one
value; never zero or more than one values. There is no fundamental
issue with it.

defines would simply be extending multisubstitute to allow using this
technique for any kind of expansion including the importas with -i,
elglob, etc. I don't think it introduces some new problems to the
technique.

o/
 emanuele6
Received on Fri May 24 2024 - 18:16:02 CEST

This archive was generated by hypermail 2.4.0 : Fri May 24 2024 - 18:16:33 CEST