bakefile icon indicating copy to clipboard operation
bakefile copied to clipboard

Allow interpolating of list in string

Open refi64 opened this issue 9 years ago • 7 comments

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?

refi64 avatar Jul 28 '14 21:07 refi64

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?

vadz avatar Jul 28 '14 22:07 vadz

I opened PR #34 for this. Forgot to mention it. Oops...

refi64 avatar Jul 29 '14 00:07 refi64

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.

vslavik avatar Jul 29 '14 09:07 vslavik

What about a list-concatenation operator? Something like:

abc = "my-cmd @(my-var, )";

It would be formatted "@(variable,sep)".

refi64 avatar Jul 29 '14 16:07 refi64

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:

  1. List interpolation into string context.
  2. Replacement function, i.e. something like GNU make $(patsubst).

vadz avatar Jul 29 '14 22:07 vadz

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...)

vslavik avatar Jul 31 '14 11:07 vslavik

See also #37.

vslavik avatar Aug 05 '14 08:08 vslavik