POV-Ray : Newsgroups : povray.beta-test : Request for Testing: Dictionaries and Arrays : Request for Testing: Dictionaries and Arrays Server Time
26 Sep 2021 12:09:33 EDT (-0400)
  Request for Testing: Dictionaries and Arrays  
From: clipka
Date: 21 Nov 2016 18:03:16
Message: <58337d34$1@news.povray.org>
Hi folks,

I'd like you to test-drive this special version, and also comment on the
syntax chosen:


Focus of this version is on data containers.

Array syntax and behaviour is extended as follows:

- Array elements no longer have to be all of the same type.
- Caveat: Mixing elements of different type will increase memory
consumption; the increased memory footprint will not revert even if the
array is later set to elements all of the same type.

- An array can be declared without specifying any dimensions; in this
case the array will be one-dimensional and be able to grow in size
- Accessing an element beyond the nominal size of such an array will
automatically increase the nominal size just enough to include that element.
- Caveat: The memory footprint may be twice as high as required for the
current nominal size.
- Caveat: Growth of such an array is triggered by /any/ access to an
element beyond the nominal size; this includes tests such as

Also, so-called "dictionaries" have been added, i.e. containers that map
string keys to arbitrary-type values; if the syntax remains as currently
implemented, it will be as follows:

    // create an empty dictionary
    #declare Fnord = dictionary;

    // create a dictionary with elements
    #declare Fnord = dictionary {
      ["Foo"]: 42,
      ["Bar"]: sphere { <0,0,0>, 1 }

    // alternative
    #declare Fnord = dictionary {
      .Foo: 42,
      .Bar: sphere { <0,0,0>, 1 }

    // access a dictionary element
    #declare Fnord["Foo"] = 42;
    #declare Answer = Fnord["Foo"];

    // alternative
    #declare Fnord.Foo = 42;
    #declare Answer = Fnord.Foo;

    // testing whether a dictionary contains a particular key
    // (e.g.)
    #ifdef (Fnord.["Foo"]) ... #end
    #declare FooKeyExists = defined(Fnord.Foo);

    // removing a key from a dictionary
    // (e.g.)
    #undef Fnord["Foo"];

When using square bracket notation, the keys do not necessarily have to
be string literals, but can be arbitrary string expressions.

When using dot notation, the indices must follow the generic rules for

Two pseudo-dictionaries are also supported: `global` and `local`,
representing the set of variables currently defined at the global scope
and the most local scope, respectively. (Note: The pseudo-functions of
the same names have been dropped.)

Post a reply to this message

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