|
|
I ran comparison tests in v3.7.0 and 3.8 beta 1, to see if the results were
consistent. They are, except with slightly different error messages when the
integer value for array[...] does not match the actual number of elements in it.
>[Leroy:]
> #declare Tab=array[4]{ 1 2 3 4 }
> #declare Sf=array[4]{"a" "b" "c" "d"}
> #declare Sf=array[4]{<1,2,3> <1,2,3> <1,2,3> <1,2,3>}
All of these parse OK, and return the correct individual values or vectors (or
any other 'things' that can be used in an array), just as if commas had been
added.
> [Cousin Ricky:]
> Be careful with this. Don't get burned by a leading '+' or '-'.
> [and Alain:]
> Like this :: #declare Tab=array[4]{ 1 -2 3 -4 }
> That parse as :: #declare Tab=array[4]{ -1, -1, 0, 0 }
This is where the situation gets interesting! I had to try and 'tease out' the
rules for this, due to the various fatal error messages I was getting...
because the size of the array did not actually match what the array
'sees' as the number of its elements, due to the added minus signs. There do
seem to be 'rules' regarding how the elements get treated as individual values--
OR *grouped together* as pairs (or triplets or whatever)-- but which are
difficult to express in words:
1) where a value is unsigned (i.e. no preceding minus sign)
2) where a negative value follows either an unsigned or neg value
3) if the 1st value is negative and the 2nd unsigned, the 1st value is 'seen' as
a single entity
Using these quasi-rules, the results are predictable-- AND the correct integer
value can be chosen for array[...].
Some examples, all of which *appear* to have 6 elements in the array:
{9 2 16 4 7 17} --- actually 6: 9 2 16 4 7 17
#declare Tab = array[6] {...}
{9 2 16 4 7 -17} --- actually 5: 9 2 16 4 (7 - 17)
#declare Tab = array[5] {...}
{-9 2 16 4 7 -17} --- actually 5: -9 2 16 4 (7 - 17)
#declare Tab = array[5] {...}
{9 -2 16 4 7 -17} --- actually 4: (9 - 2) 16 4 (7 - 17)
#declare Tab = array[4] {...}
{9 -2 16 -4 7 -17} --- actually 3: (9 - 2) (16 - 4) (7 - 17)
#declare Tab = array[3] {...}
{9 -2 -16 -4 -7 17} --- actually 2: (9 -2 -16 -4 -7) 17
#declare Tab = array[2] {...}
{-9 -2 16 -4 -7 -17} --- actually 2: (-9 -2) (16 -4 -7 -17)
#declare Tab = array[2] {...}
{9 -2 -16 -4 -7 -17} --- actually 1: (9 -2 -16 -4 -7 -17)
#declare Tab = array[1] {...}
{-9 -2 -16 -4 -7 -17} --- actually 1: (-9 -2 -16 -4 -7 -17)
#declare Tab = array[1] {...}
> [Alain:]
> Or this :: #declare Tab=array[4]{ +1 -2 +3 -4 }
> That parse as :: #declare Tab=array[4]{ -2, 0, 0, 0 }
When ALL of the values are signed, they behave as a single result, as
simple addition:
(1 - 2 +3 -4) or -2
#declare Tab = array[1] {...}
-------
For testing:
// The ending count here needs to change, to match the
// particular array[...] integer value - 1 (because an array begin at its
// zero index).
#for(i,0,0)
#debug concat("\n","Tab array value = ",str(Tab[i],0,0),"\n")
#end
------
By the way, I got three different (fatal) error messages, while testing these
examples to find the correct integer value for array[...]:
1) "Expected 4 initializers but only 2 found" -- This happens in v3.8 beta 1
when the integer for array[...] is too HIGH.
2) "Attempted to redefine float identifier as object identifier." -- This
happens in v3.7.0 when the integer for array[...] is too HIGH.
3) "No matching } in '{', float function 'float constant' found
instead" (in v3.7.0);
OR
"No matching }, float function found instead" (in v3.8 beta 1)
This means that the integer for array[...] is too LOW.
Of course, all of this was just a fun little exercise because I was curious. I
can't see a use for leaving out the commas in arrays-- except to purposely make
a piece of code difficult to understand! :-O
Post a reply to this message
|
|