Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding make-style multivalue assignments #1908

Closed
wants to merge 9 commits into from

Conversation

gyreas
Copy link
Contributor

@gyreas gyreas commented Feb 17, 2024

This PR adds support for one of the iconic features of Makefiles: multivalued assignments, where a single variable holds a list of values separated by whitespace.
The trick is to make key := value a special case of key := value1 value2 ..., which is the easiest way out.

This PR hopefully enables new use cases for Just.

EDIT:
Broken tests are now passing.
A follow-up PR will enable Just functions to operate on multivalued variables and add more Just functions that work on multivalued variables. Another one will make variables modifiable with += syntax (or something similar).

Closes #1889

@gyreas gyreas marked this pull request as ready for review February 17, 2024 03:31
@casey
Copy link
Owner

casey commented Feb 17, 2024

Thanks for the PR! I might be missing something, but I don't think that this buys us very much. It's essentially a shortcut for creating space-separated variables. As is, I don't think it's very useful, and would much prefer using #11 to do that.

@casey casey closed this Feb 17, 2024
@gyreas
Copy link
Contributor Author

gyreas commented Feb 17, 2024

I guess I misunderstood some things. I can't find the branch you referenced in #11, tho. Also, I'll shift my focus to porting some convenience functions from make, then. Furthermore, I'll probably look into #11 later on.

@casey
Copy link
Owner

casey commented Feb 18, 2024

The main issue is that if we add:

foo := bar baz

But all it's really doing is:

foo := bar + " " + baz

Then it's not very useful.

My point about formatting strings is that if the user wants a space-separated list, they could do:

foo := f'{bar} {baz}'

Which seems nicer than extending the grammar.

I think that when people want lists of things, the thing that makes them useful is the ability to access elements of the list, modify the list, and perform other operations on the list:

foo := ["a", "b"]
bar := foo[0]
baz := foo[1]
all := join(foo, " ")

The issue with that, however, is that in order to figure out if foo[0] is allowed, just would need to know whether foo is a string or a list of strings. This would require a more advanced type system than just currently has. Currently, just has a static type system, in the sense that it knows which variables exist, but all variables have type string, so this would require extending just to allow multiple types of variables, and to allow both strings and lists of string. This is desirable, but it's a much bigger change.

#11 is an issue for allowing interpolation inside of strings, so you could do something like f'{foo} and {bar}', so you could interpolate inside of strings instead of having to do foo + " and " + bar, which is longer and more annoying.

@gyreas
Copy link
Contributor Author

gyreas commented Feb 21, 2024

I understand. I can't tackle it right now, however; instead, I'll work on adding more convenience functions from make. Are cool with that?

@casey
Copy link
Owner

casey commented Feb 21, 2024

Of course! If there's something you want to add, open an issue first to discuss the feature and design, so we can make sure it's something that'll get merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Array variables
2 participants