POV-Ray : Newsgroups : povray.advanced-users : Hash arrays working yet? : Re: Hash arrays working yet? Server Time
20 Apr 2024 01:15:55 EDT (-0400)
  Re: Hash arrays working yet?  
From: clipka
Date: 12 Sep 2018 23:37:52
Message: <5b99db90$1@news.povray.org>
Am 13.09.2018 um 01:32 schrieb Mike Horvath:
> I know arrays have undergone some work recently.
> 
> 1. Are hash arrays working now?

That depends on what exactly you mean by "hash array".

If you want associative arrays with arbitrary keys, the answer is "Nope".

If you are fine with string keys then the answer is "Sure". Search the
Wiki for "dictionary".

In a nutshell:

    // requires POV-Ray v3.8
    #version 3.8;

    // create a dictionary
    #declare Foo = dictionary;

    // associate key "Fnord" with value 42
    #declare Foo["Fnord"] = 42;
    #declare Bar = "Fnord";
    #declare Foo[Bar] = 42
    #declare Foo.Fnord = 42;

    // look up value associated with key "Fnord"
    #declare Result = Foo["Fnord"];

    // test if key "Fnord" has a value associated
    #ifdef (Foo["Fnord"]) ... #end

    // remove key "Fnord" from dictionary
    #undef (Foo["Fnord"])


> 2. Can an array contain different types of objects? (string, float, int,
> etc.)

Yep. No extra syntax required (but POV-Ray v3.8 is needed).


3. Can an array be resized?

Yes, but only if it is one-dimensional, and it has to be declared using
a special syntax (note the missing size):

    #declare Foo = array[];


> My POV version is 3.8.0-alpha.9475849+av541.msvc14.win64.

I recommend a newer version; but dictionaries and new array features
should be in there already.


Post a reply to this message

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