[Omake] semantics of +=
Aleksey Nogin
nogin at metaprl.org
Wed Sep 20 16:04:19 PDT 2006
On 20.09.2006 05:09, David Kågedal wrote:
> I was confused for a while when my omake started hanging. The problem
> was that I had something like this in my OMakefile:
>
> FILES[] =
> a
> b
>
> FILES +=
> lex
> hex
> mex
>
> Try to spot the error! Actually I thought this was a valid way to add
> to an array, but apparently not. But how is this syntax interpreted?
>
In addition to what Jason said, keep in mind that there are two
considerations - "static" (when the file is read and parsed) and
"dynamic" (when the commands in the file are actually executed). The
static consideration simply looks for the "[]" after the variable name
in the assignment operator. If there is a "[]" and the assignment has a
body, that body gets interpreted as an array. In other words, statically,
FILES[] =
a
b
is essentially equivalent to
FILES = $(array a, b)
and
FILES[] +=
ab
cd
ef
is essentially equivalent to
FILES += $(array ab, cd, ef)
So the "[]" is simply a syntactic sugar.
On the other hand, there is a dynamic consideration as well - whenever
you do
VAR += expr
whenever _either_ the value of the variable VAR before the "+=" is an
array, _or_ the expression "expr" evaluates to the array value (and here
is does not matter whether expr was created using syntactic sugar or
not), then the resulting value of the variable VAR will be an array.
More information about the Omake
mailing list