On Mon, Jan 22, 2024 at 2:16 PM Paul Smith <psm...@gnu.org> wrote: > > If the only goal was to allow +:= create a simple variable, then can > > we do the following? > > "If no variable with this name exists, then +:= creates a simple > > variable, and +:::= creates an immediately-expanded-and-escaped > > variable. Otherwise, +:= and +:::= behave the same as +=". > > If we go with this, then there is no need for +!=, because +!= would > > behave as +=. Similarly, there is no need for +::=, because +::= > > would behave as +:=. > > I agree that we don't need to treat +:= and +::= differently. They are > just different names for the same operator. > ... > > The variable assignment operators describe two things: how to handle > the RHS value and what the resulting flavor of the variable will be. > Although we have four assignment operators, once the assignment is > complete there are only two flavors of variables: either recursive or > simple: > > = - Don't expand the RHS, --> recursive variable > := - Expand the RHS, --> simple variable > ::= - Expand the RHS, --> simple variable > :::= - Expand and escape the RHS, --> recursive variable > != - Run the RHS as a shell script, --> recursive variable. > > If an appending operator is applied to a variable that doesn't exist > already, then the behavior is the same as if we used the non-appending > operator in all cases. So if the variable doesn't exist, "+=" behaves > like "=", "+:=" behaves like ":=", "+::=" behaves like "::=", "+:::=" > behaves like ":::=", and "+!=" behaves like "!=". That's simple. > > What about a variable that does exist already? > > I think that we can agree that the append operator cannot change the > type of a variable that already exists. If the variable was recursive > before it must stay recursive afterward; the same for simple variables.
Why is that? Why not say X +:= Y behaves similar to X := $(X) $(Y) (the difference being that the space is added only if X is nonempty)? That would make documentation simpler. I was impressed by the realization that + can be treated as an assignment modifier just like ?. I expect that someone will inevitably ask for !:= as well, even though ! cannot be considered an assignment modifier. How far do we go? "+!:=" could mean append simply expanded shell output to a variable that retains its type. "+:!:=" could mean append simply expanded shell output to a simply expanded variable. ugh... Regards, - Jouke