Hi folks,
I'd like you to test-drive this special version, and also comment on the
syntax chosen:
https://github.com/POV-Ray/povray/releases/tag/v3.7.1-x.dictionary.8884712
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
dynamically.
- 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
`#ifdef(ARRAY[INDEX])`.
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
identifiers.
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.)