POV-Ray : Newsgroups : povray.general : funky array thing Server Time
11 Oct 2024 16:14:29 EDT (-0400)
  funky array thing (Message 1 to 8 of 8)  
From: Leroy
Subject: funky array thing
Date: 22 Aug 2024 15:55:00
Message: <web.66c79364b339270949d5a218f712fc00@news.povray.org>
I have POV version 3.7.0.msvgc10.win64
While editing a file I pasted a set of numbers into an array from a text file.

Like this :: #declare Tab=array[4]{ 1 2 3 4 }

I was going to go back and put commas in but forgot and ran it anyway and It
still worked!

So I tried ::
#declare Sf=array[4]{"a" "b" "c" "d"}
#declare Sf=array[4]{<1,2,3> <1,2,3> <1,2,3> <1,2,3>}

They  also worked !

Learn something new every day!
Have Fun!


Post a reply to this message

From: Cousin Ricky
Subject: Re: funky array thing
Date: 22 Aug 2024 22:51:22
Message: <66c7f92a$1@news.povray.org>
On 2024-08-22 15:53 (-4), Leroy wrote:
> 
> Like this :: #declare Tab=array[4]{ 1 2 3 4 }
> 
> I was going to go back and put commas in but forgot and ran it anyway and It
> still worked!
> 
> So I tried ::
> #declare Sf=array[4]{"a" "b" "c" "d"}
> #declare Sf=array[4]{<1,2,3> <1,2,3> <1,2,3> <1,2,3>}
> 
> They  also worked !

Be careful with this.  Don't get burned by a leading '+' or '-'.


Post a reply to this message

From: Alain Martel
Subject: Re: funky array thing
Date: 23 Aug 2024 07:52:57
Message: <66c87819$1@news.povray.org>
Le 2024-08-22 à 22:51, Cousin Ricky a écrit :
> On 2024-08-22 15:53 (-4), Leroy wrote:
>>
>> Like this :: #declare Tab=array[4]{ 1 2 3 4 }
>>
>> I was going to go back and put commas in but forgot and ran it anyway and It
>> still worked!
>>
>> So I tried ::
>> #declare Sf=array[4]{"a" "b" "c" "d"}
>> #declare Sf=array[4]{<1,2,3> <1,2,3> <1,2,3> <1,2,3>}
>>
>> They  also worked !
> 
> Be careful with this.  Don't get burned by a leading '+' or '-'.
> 
Like this :: #declare Tab=array[4]{ 1 -2 3 -4 }
That parse as :: #declare Tab=array[4]{ -1, -1, 0, 0 }
Or this :: #declare Tab=array[4]{ +1 -2 +3 -4 }
That parse as :: #declare Tab=array[4]{ -2, 0, 0, 0 }


Post a reply to this message

From: Leroy
Subject: Re: funky array thing
Date: 23 Aug 2024 22:15:00
Message: <web.66c9418a710883073c8d69f0f712fc00@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:
> > On 2024-08-22 15:53 (-4), Leroy wrote:
> >>
> >> Like this :: #declare Tab=array[4]{ 1 2 3 4 }
> >>
> >> I was going to go back and put commas in but forgot and ran it anyway and It
> >> still worked!
> >>
> >> So I tried ::
> >> #declare Sf=array[4]{"a" "b" "c" "d"}
> >> #declare Sf=array[4]{<1,2,3> <1,2,3> <1,2,3> <1,2,3>}
> >>
> >> They  also worked !
> >
> > Be careful with this.  Don't get burned by a leading '+' or '-'.
> >
> Like this :: #declare Tab=array[4]{ 1 -2 3 -4 }
> That parse as :: #declare Tab=array[4]{ -1, -1, 0, 0 }
> Or this :: #declare Tab=array[4]{ +1 -2 +3 -4 }
> That parse as :: #declare Tab=array[4]{ -2, 0, 0, 0 }

More funk!
I didn't think about trying negative numbers!
Won't be using that little trick for much.
It was just something I wasn't expecting.


Post a reply to this message

From: Kenneth
Subject: Re: funky array thing
Date: 4 Sep 2024 09:25:00
Message: <web.66d85dfe7108830791c33a706e066e29@news.povray.org>
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

From: Leroy
Subject: Re: funky array thing
Date: 4 Sep 2024 16:55:00
Message: <web.66d8c83b71088307cacbd0d2f712fc00@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> 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

My first thought Bond, JAMES BOND.


Post a reply to this message

From: Leroy
Subject: Re: funky array thing
Date: 4 Sep 2024 17:10:00
Message: <web.66d8cc3371088307cacbd0d2f712fc00@news.povray.org>
Sorry, I couldn't resist, after seeing what you have done!
I had to test the array[4]{2 1 * 2 1 / 3 4} It works!
I think it works because Like the + - in your examples POV thinks they are
mathematical functions.
Have Fun!


Post a reply to this message

From: Kenneth
Subject: Re: funky array thing
Date: 4 Sep 2024 23:50:00
Message: <web.66d929c57108830791c33a706e066e29@news.povray.org>
"Leroy" <whe### [at] gmailcom> wrote:

>
> My first thought Bond, JAMES BOND.

Ha! YES, I had a similar thought: Including 'secret' math expressions in scene
code, so that only 'the most knowledgeable' among us would be able to decipher
or reverse-engineer them. But now that the rules are 'laid bare' (well, so far),
these 'decipher keys' are no longer a secret! :-(

By the way, I didn't think to test multiplication or division within the array
elements, like you did; I need to give that a try, to see what pops up.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.