[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #54703] Incorrection expansion of := accumulator under $(eval …)
From: |
Michael Builov |
Subject: |
[bug #54703] Incorrection expansion of := accumulator under $(eval …) |
Date: |
Fri, 21 Sep 2018 11:50:16 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0 |
Follow-up Comment #1, bug #54703 (project make):
Hello.
This is not a bug.
Argument of eval is always expanded prior evalation.
Let's see how this works.
---------
ITERATIONS:=1 2 3
ACCUMULATOR:=Macron go home :
WORD_1:=Macron
WORD_2:=go
WORD_3:=home
define ACCUMULATE
WORD:=$(WORD_$(1))
ACCUMULATOR:=$(ACCUMULATOR) $(WORD)
endef
$(foreach ITERATION,$(ITERATIONS),$(eval $(call ACCUMULATE,$(ITERATION))))
---------
* The first foreach iteration is expanded as:
WORD:=Macron
ACCUMULATOR:=Macron go home : <empty>
then evaluated
* second iteration is expanded as:
WORD:=go
ACCUMULATOR:=Macron go home : Macron
then evaluated
* third iteration is expanded as:
WORD:=home
ACCUMULATOR:=Macron go home : Macron go
and then evaluated.
-------
You need to delay expansion of $(WORD) in the ACCUMULATE until eval:
define ACCUMULATE
WORD:=$(WORD_$(1))
ACCUMULATOR:=$(ACCUMULATOR) $$(WORD)
endef
then, while processing assignment operator :=, eval expands the value a second
time
-------
For debugging, it is handy to trace eval calls, e.g.:
trace_eval = $(info $1)$(eval $1)
$(foreach ITERATION,$(ITERATIONS),$(call trace_eval,$(call
ACCUMULATE,$(ITERATION))))
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?54703>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/