POV-Ray : Newsgroups : povray.documentation.inbuilt : dictionary container types : Re: dictionary container types Server Time
14 Aug 2022 23:08:47 EDT (-0400)
  Re: dictionary container types  
From: clipka
Date: 19 Nov 2016 14:26:53
Message: <5830a77d$1@news.povray.org>
Am 19.11.2016 um 16:38 schrieb Jim Holsenback:
> from discussion Classes/containers in sdl? in p.advanced-users i know
> for a fact that this hasn't been added to docs either ... it was
> mentioned that the syntax is still in flux. i just wanted to post here
> as a reminder to follow up. @Bill ... would you mind following up with a
> link so i can have a look at what we have so far and /maybe/ get started
> on that ... thanks in advance

It's not in the main branch yet, so should probably not be added to the
docs yet; however, for the records:

Arrays will be modified as follows:

- Array elements will 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" will be 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

Post a reply to this message

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