[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Conditional append operator (was: Re: New conditional assignment facilit
From: |
Paul Smith |
Subject: |
Conditional append operator (was: Re: New conditional assignment facility) |
Date: |
Sat, 03 Feb 2024 17:45:12 -0500 |
User-agent: |
Evolution 3.50.3 (by Flathub.org) |
On Mon, 2024-01-29 at 09:52 +0000, Edward Welbourne wrote:
> Perhaps it would be useful to enumerate the other types of assignment
This seems useful. There are two options: the "append changes the type
of the variable" option, and the "append doesn't change the type of the
variable" option. Since := and ::= have identical behavior I didn't
show both in the examples below.
Here's how I think the "append changes the type of the variable" option
works:
Given:
v1 = a$$b
v2 = x$$y
FOO = $(v1)
FOO += $(v2) equals FOO = $(v1) $(v2)
FOO := $(v1)
FOO += $(v2) equals FOO := a$b x$y
FOO = $(v1)
FOO +:= $(v2) equals FOO := a$b x$y
FOO := $(v1)
FOO +:= $(v2) equals FOO := a$b x$y
FOO = $(v1)
FOO +:::= $(v2) equals FOO = a$$b x$$y
FOO := $(v1)
FOO +:::= $(v2) equals FOO = a$$b x$$y
FOO = $(v1) ??? not sure. Maybe:
FOO +!= echo '$(v2)' equals FOO = $(v1) x$$y
???
FOO := $(v1) ??? not sure. Maybe:
FOO +!= echo '$(v2)' equals FOO = a$$b x$$y
???
Note that in all cases except the first (and !+=?), if the variables v1
or v2 were reset AFTER this assignment that change would have no effect
on FOO. What this means is that you cannot use any assignment / append
operator other than "=" and "+=" (and maybe "+!="?) with any variable
that needs to contain an automatic variable like "$@" or "$<".
An algorithm for the above non-+= operators might be something like:
1. Find the RHS type (simple vs. recursive) based on the append
operator.
2. Evaluate the RHS of the variable as per its operator
3. If the LHS == simple && RHS == recursive: escape the LHS
4. If the LHS == recursive && RHS == simple: expand the LHS
5. Append the LHS and RHS values separated by a space
6. Set the type of the variable to the RHS type
Here's how I think the "append doesn't change the type of the variable"
option works:
Given:
v1 = a$$b
v2 = x$$y
FOO = $(v1)
FOO += $(v2) equals FOO = $(v1) $(v2)
FOO := $(v1)
FOO += $(v2) equals FOO := a$b x$y
FOO = $(v1)
FOO +:= $(v2) equals FOO = $(v1) x$$y
FOO := $(v1)
FOO +:= $(v2) equals FOO := a$b x$y
FOO = $(v1)
FOO +:::= $(v2) equals FOO = $(v1) x$$y
FOO := $(v1)
FOO +:::= $(v2) equals FOO := a$b x$y
FOO = $(v1)
FOO +!= echo '$(v2)' equals FOO = $(v1) x$y
FOO := $(v1)
FOO +!= echo '$(v2)' equals FOO := a$b x
An algorithm for the above non-+= operators might be something like:
1. Find the RHS type (simple vs. recursive) based on the append
operator.
2. Evaluate the RHS of the variable as per its operator
3. If the LHS == simple && RHS == recursive: expand the RHS
4. If the LHS == recursive && RHS == simple: escape the RHS
5. Append the LHS and RHS values separated by a space
6. Don't change the type of the variable
--
Paul D. Smith <psmith@gnu.org> Find some GNU Make tips at:
https://www.gnu.org http://make.mad-scientist.net "Please remain
calm...I may be mad, but I am a professional." --Mad Scientist
- Conditional append operator (was: Re: New conditional assignment facility),
Paul Smith <=