POV-Ray : Newsgroups : povray.general : Dictionaries and arrays Server Time
26 Dec 2024 21:35:40 EST (-0500)
  Dictionaries and arrays (Message 1 to 4 of 4)  
From: Chris R
Subject: Dictionaries and arrays
Date: 28 Sep 2023 08:25:00
Message: <web.65156ffd8732a5d977c596b55cc1b6e@news.povray.org>
Despite the fact that I've been playing with v3.7 and v3.8 for several years
now, I just discovered the dictionary feature in POV-Ray.

I come from a C/Java programming background, so most of my work is done by
creating macros and then invoking them in the top level scene file.  The macros
often have parameters so they can be used in multiple places in the scene, or
for animation purposes.  However, there are times when objects have too many
configurable parameters to comfortably list all of them in the macro.

Previously, I would create an array and declare the positions in that array to
hold configurable parameters.  This was fine as long as all of the parameters
were of the same type, (i.e. numbers, strings, vectors, etc.).  However, if I
needed a mix, then I ended up with separate arrays for each type.

And then I discovered dictionaries, which do exactly what I needed.  I was even
more delighted to find that dictionaries could hold other dictionaries, and the
foo.bar.baz.color dot notation works as expected to a C programmer.

However, while reading the documentation on dictionaries, which is listed with
array documentation, I found the new "mixed" keyword (3.8) for array
declarations, which allows you to put a mixed set of values in a single array.

I am going to keep using dictionaries, because I think the syntax is more
natural to me, and I don't have to keep track of index positions within an
array.  But, is there any practical advantage to using a mixed array over a
dictionary?  Or is it just a matter of personal syntactic taste?

-- Chris R.


Post a reply to this message

From: Bald Eagle
Subject: Re: Dictionaries and arrays
Date: 28 Sep 2023 13:40:00
Message: <web.6515b9e4e22320151f9dae3025979125@news.povray.org>
"Chris R" <car### [at] comcastnet> wrote:

> I am going to keep using dictionaries, because I think the syntax is more
> natural to me, and I don't have to keep track of index positions within an
> array.  But, is there any practical advantage to using a mixed array over a
> dictionary?  Or is it just a matter of personal syntactic taste?

I can't speak for anyone but myself -

For a while, all we had were standard arrays that only accepted a single data
type.
Then Jaap Frank discovered that if you had several arrays of different types,
those could be packaged into a single array, because doing it in that 2-step
process fooled POV-Ray and gave you an array of arrays, even though it was
functionally the same as a mixed array.

Then we got dictionaries, and jr was happy.

The end.

:)

Actually, I often use mixed arrays as a sort of parameter input for macros, so
having a mixed array helps.
Also, for the longest time we didn't have tuple-style variable assignment, and
so passing multiple values out of arrays was problematic.   I would (ab)use
vectors for that, or use the array of arrays workaround, but mixed arrays makes
passing a wide variety of results of different data types much easier.

- BW


Post a reply to this message

From: jr
Subject: Re: Dictionaries and arrays
Date: 29 Sep 2023 00:15:00
Message: <web.65164e35e2232015b180e2cc6cde94f1@news.povray.org>
hi,

"Chris R" <car### [at] comcastnet> wrote:
> Despite the fact that I've been playing with v3.7 and v3.8 for several years
> now, I just discovered the dictionary feature in POV-Ray.

</grin>


> ... But, is there any practical advantage to using a mixed array over a
> dictionary?  Or is it just a matter of personal syntactic taste?

"horses for courses"..  one neat thing with a dictionary is that POV-Ray allows
choice of syntax.  while I too like (and prefer) the a.b.c notation, using the
array notation does have an advantage because the key in a["b"] can be a
variable.  (I use 'array mixed' mostly when thinking "list").


btw the heightfield image ?  ~186 seconds per pixel.. :-)


regards, jr.


Post a reply to this message

From: Chris R
Subject: Re: Dictionaries and arrays
Date: 29 Sep 2023 11:45:00
Message: <web.6516f0c0e2232015f70585b5cc1b6e@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> "Chris R" <car### [at] comcastnet> wrote:
> > Despite the fact that I've been playing with v3.7 and v3.8 for several years
> > now, I just discovered the dictionary feature in POV-Ray.
>
> </grin>
>
>
> > ... But, is there any practical advantage to using a mixed array over a
> > dictionary?  Or is it just a matter of personal syntactic taste?
>
> "horses for courses"..  one neat thing with a dictionary is that POV-Ray allows
> choice of syntax.  while I too like (and prefer) the a.b.c notation, using the
> array notation does have an advantage because the key in a["b"] can be a
> variable.  (I use 'array mixed' mostly when thinking "list").
>
>
> btw the heightfield image ?  ~186 seconds per pixel.. :-)
>
>
> regards, jr.

I noted the two notations for dictionaries as well.  I've found some cases
already where it would be useful to use the array notation.

As for the heightfield image, that was after taking a bunch of hints from others
in this newsgroup about how to speed up renders, (e.g. reducing my default
max_trace_level from 30 to 10!).  It doesn't seem that radiosity computations
were significant, so I'm assuming it still all has to do with the vast number of
reflections in a turbulent water scheme with a highly turbulent surrounding
terrain.

-- Chris R.


Post a reply to this message

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