POV-Ray : Newsgroups : povray.general : Dictionaries and arrays : Dictionaries and arrays Server Time
9 May 2024 19:08:05 EDT (-0400)
  Dictionaries and arrays  
From: Chris R
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

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