POV-Ray : Newsgroups : povray.beta-test : Request for Testing: Dictionaries and Arrays Server Time
29 Mar 2024 02:32:58 EDT (-0400)
  Request for Testing: Dictionaries and Arrays (Message 1 to 3 of 3)  
From: clipka
Subject: Request for Testing: Dictionaries and Arrays
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:

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.)


Post a reply to this message

From: Mike Horvath
Subject: Re: Request for Testing: Dictionaries and Arrays
Date: 21 Nov 2016 18:48:33
Message: <583387d1$1@news.povray.org>
On 11/21/2016 6:03 PM, clipka wrote:
>     // testing whether a dictionary contains a particular key
>     // (e.g.)
>     #ifdef (Fnord.["Foo"]) ... #end
>     #declare FooKeyExists = defined(Fnord.Foo);

Should that be Fnord["Foo"] instead of Fnord.["Foo"]?

Mike


Post a reply to this message

From: clipka
Subject: Re: Request for Testing: Dictionaries and Arrays
Date: 22 Nov 2016 02:04:18
Message: <5833edf2$1@news.povray.org>
Am 22.11.2016 um 00:48 schrieb Mike Horvath:
> On 11/21/2016 6:03 PM, clipka wrote:
>>     // testing whether a dictionary contains a particular key
>>     // (e.g.)
>>     #ifdef (Fnord.["Foo"]) ... #end
>>     #declare FooKeyExists = defined(Fnord.Foo);
> 
> Should that be Fnord["Foo"] instead of Fnord.["Foo"]?

Yes, of course. Well spotted.


Post a reply to this message

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