POV-Ray : Newsgroups : povray.advanced-users : Hash arrays working yet? Server Time
21 Dec 2024 21:45:02 EST (-0500)
  Hash arrays working yet? (Message 1 to 8 of 8)  
From: Mike Horvath
Subject: Hash arrays working yet?
Date: 12 Sep 2018 19:31:54
Message: <5b99a1ea$1@news.povray.org>
I know arrays have undergone some work recently.

1. Are hash arrays working now?
2. Can an array contain different types of objects? (string, float, int, 
etc.)

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

Thanks.


Mike


Post a reply to this message

From: Mike Horvath
Subject: Re: Hash arrays working yet?
Date: 12 Sep 2018 20:42:34
Message: <5b99b27a@news.povray.org>
I am trying to define an array like this:

#declare MeanAnomalyToday = array[8]
{
CalcMeanAnomalyToday(0),
CalcMeanAnomalyToday(1),
CalcMeanAnomalyToday(2),
CalcMeanAnomalyToday(3),
CalcMeanAnomalyToday(4),
CalcMeanAnomalyToday(5),
CalcMeanAnomalyToday(6),
CalcMeanAnomalyToday(7)
}

The macro "CalcMeanAnomalyToday" returns a number.

#macro CalcMeanAnomalyToday(i)
   2 * i
#end

I get an error, "Parse Error: Expected 'array initializer element', 
macro identifier found instead".

What am I doing incorrectly? Thanks.


Mike


Post a reply to this message

From: clipka
Subject: Re: Hash arrays working yet?
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

From: Mike Horvath
Subject: Re: Hash arrays working yet?
Date: 13 Sep 2018 00:21:43
Message: <5b99e5d7@news.povray.org>
I guess I've run into another one of those "macros aren't functions" 
situations.


Mike


Post a reply to this message

From: clipka
Subject: Re: Hash arrays working yet?
Date: 13 Sep 2018 00:25:42
Message: <5b99e6c6$1@news.povray.org>
Am 13.09.2018 um 02:42 schrieb Mike Horvath:
> I am trying to define an array like this:
> 
> #declare MeanAnomalyToday = array[8]
> {
> CalcMeanAnomalyToday(0),
> CalcMeanAnomalyToday(1),
> CalcMeanAnomalyToday(2),
> CalcMeanAnomalyToday(3),
> CalcMeanAnomalyToday(4),
> CalcMeanAnomalyToday(5),
> CalcMeanAnomalyToday(6),
> CalcMeanAnomalyToday(7)
> }
> 
> The macro "CalcMeanAnomalyToday" returns a number.
> 
> #macro CalcMeanAnomalyToday(i)
>   2 * i
> #end
> 
> I get an error, "Parse Error: Expected 'array initializer element',
> macro identifier found instead".
> 
> What am I doing incorrectly? Thanks.

In a nutshell, POV-Ray doesn't like anything fancy in array initializers
- no macros, no #for loops, no #if statements, no nothing.

That's a long-standing featuroid, which a certain previous member of the
dev team would probably dismiss as entirely intentional; I for one would
call it a shortcoming that /should/ be fixed, but I'd rather not touch
the professional-league Jenga tower of code in which this issue is rooted.

https://youtu.be/7erl-bOWmOM


Post a reply to this message

From: BGimeno
Subject: Re: Hash arrays working yet?
Date: 19 Sep 2018 05:38:07
Message: <5ba218ff$1@news.povray.org>
El 13/09/18 a las 01:32, Mike Horvath escribió:
> I know arrays have undergone some work recently.
> 
> 1. Are hash arrays working now?
> 2. Can an array contain different types of objects? (string, float, int, 
> etc.)
> 
> My POV version is 3.8.0-alpha.9475849+av541.msvc14.win64.
> 
> Thanks.
> 
> 
> Mike

  I was now immersed in the same situation and I thought that dictionary 
(working as an array) would save this obstacle, but as not seeing it in 
the list of reserved words in version 3.7 I guess it must have been removed.

B.Gimeno


Post a reply to this message

From: clipka
Subject: Re: Hash arrays working yet?
Date: 19 Sep 2018 06:00:27
Message: <5ba21e3b$1@news.povray.org>
Am 19.09.2018 um 11:38 schrieb BGimeno:
> El 13/09/18 a las 01:32, Mike Horvath escribió:
>> I know arrays have undergone some work recently.
>>
>> 1. Are hash arrays working now?
>> 2. Can an array contain different types of objects? (string, float,
>> int, etc.)
>>
>> My POV version is 3.8.0-alpha.9475849+av541.msvc14.win64.
>>
>> Thanks.
>>
>>
>> Mike
> 
>  I was now immersed in the same situation and I thought that dictionary
> (working as an array) would save this obstacle, but as not seeing it in
> the list of reserved words in version 3.7 I guess it must have been
> removed.

Um - nope?!

v3.7.0 never had `dictionary`. It only made its debut in v3.7.1 (some
alpha version) which was later re-branded v3.8.0.


Post a reply to this message

From: BGimeno
Subject: Re: Hash arrays working yet?
Date: 19 Sep 2018 08:58:13
Message: <5ba247e5$1@news.povray.org>
El 19/09/18 a las 12:00, clipka escribió:
>> the list of reserved words in version 3.7 I guess it must have been
>> removed.
> 
> Um - nope?!
> 
> v3.7.0 never had `dictionary`. It only made its debut in v3.7.1 (some
> alpha version) which was later re-branded v3.8.0.
> 

I have been revising the documentation too many times and in the end I 
see things where there are none. My source of information is in the 
following link, you are right, my apologies.

http://news.povray.org/povray.documentation.inbuilt/thread/%3C584fbc8e%241%40news.povray.org%3E/


BGimeno


Post a reply to this message

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