bakefile
bakefile copied to clipboard
Allow interpolating of list in string
I have a Bakefile that has a section like this:
tests = test_a test_b test_c;
action run_tests {
deps = my_library $(tests);
commands = "python ../tests/test_runner.py $(tests)";
}
However, the $(tests)
doesn't work:
bakefile.bkl:30:8: error: variable "commands" (list of strings): expression "[test_pstring, test_plist, test_pp]" is not a valid string value
To me, this shouldn't be an error. It isn't uncommon to interpolate a list of strings into a string like this. Could this be added?
I don't really see any reason to not allow interpolating the lists like this, even though I also think it's not a big deal to use quotes around the string if you really want to use it as a string. @vslavik what do you think?
I opened PR #34 for this. Forgot to mention it. Oops...
I don't really see any reason to not allow interpolating the lists like this
Yes, I think it does make sense, but not the way #34 does it (see over there).
It's not entirely clear-cut, BTW, because space is not the universal list delimiter: VS uses ;
in projects, but any external invocation would use a space. Still, I do agree that interpolation should use it.
I also think it's not a big deal to use quotes around the string
In this example, yes, but I suppose the variable could be a list of files (where quoting wouldn't interpret them as paths), possibly composed from sub-variables.
What about a list-concatenation operator? Something like:
abc = "my-cmd @(my-var, )";
It would be formatted "@(variable,sep)".
Honestly, this doesn't seem intuitive at all to me. Unfortunately I don't know any really natural syntax for it. FWIW zsh uses ${(j:sep:)my-var}
and while I'm not going to pretend it's especially clear neither, at least it has a precedent.
I think it might be better to have two orthogonal things instead:
- List interpolation into string context.
- Replacement function, i.e. something like GNU make
$(patsubst)
.
List interpolation into string context.
Yes, using space by default is perfectly fine.
Replacement function, i.e. something like GNU make $(patsubst).
And this is better than special syntax for the unusual stuff, because functions should exist for other uses as well. (As a matter of fact, implementing list substitution would be probably easier via a function too...)
See also #37.