POV-Ray : Newsgroups : povray.beta-test : I have a hunch some of you may like this... Server Time
9 Oct 2026 01:22:59 EDT (-0400)
  I have a hunch some of you may like this... (Message 1 to 21 of 21)  
From: clipka
Subject: I have a hunch some of you may like this...
Date: 17 Sep 2016 13:11:23
Message: <57dd793b$1@news.povray.org>
#declare MyFrobnitz = dictionary;
#declare MyFrobnitz.Foo = 42;
#declare MyFrobnitz.Bar = "FTW!";

Need I say more?

Oh, yes, of couse:

https://github.com/POV-Ray/povray/releases/tag/v3.7.1-x.dictionary.8790760


Future plans:

- Support for an array-like syntax, e.g. `MyFrobnitz["Foo"]` (originally
intended to be the primary syntax, with the dot notation planned as a
later syntactic sugar extension, but the parser's internals got in my
way, so I decided to go for the easier part first)

- Support for initializers (if you have any suggestions for the syntax
to be used, please let me know)


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 14:17:57
Message: <57dd88d5$1@news.povray.org>
On 9/17/2016 1:11 PM, clipka wrote:
> #declare MyFrobnitz = dictionary;
> #declare MyFrobnitz.Foo = 42;
> #declare MyFrobnitz.Bar = "FTW!";
>
> Need I say more?
>
> Oh, yes, of couse:
>
> https://github.com/POV-Ray/povray/releases/tag/v3.7.1-x.dictionary.8790760
>
>
> Future plans:
>
> - Support for an array-like syntax, e.g. `MyFrobnitz["Foo"]` (originally
> intended to be the primary syntax, with the dot notation planned as a
> later syntactic sugar extension, but the parser's internals got in my
> way, so I decided to go for the easier part first)
>
> - Support for initializers (if you have any suggestions for the syntax
> to be used, please let me know)
>

Will there be a shorthand syntax too? Like:

MyFrobnitz =
{
	Foo = 42,
	Bar = "FTW!"
}


Mike


Post a reply to this message

From: tth
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 15:01:27
Message: <57dd9307$1@news.povray.org>
On 09/17/2016 07:11 PM, clipka wrote:
> #declare MyFrobnitz = dictionary;
> #declare MyFrobnitz.Foo = 42;
> #declare MyFrobnitz.Bar = "FTW!";
>
> Need I say more?

   No, it's Ok for me.


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 15:25:26
Message: <57dd98a6$1@news.povray.org>
On 9/17/2016 1:11 PM, clipka wrote:
> #declare MyFrobnitz = dictionary;
> #declare MyFrobnitz.Foo = 42;
> #declare MyFrobnitz.Bar = "FTW!";
>
> Need I say more?
>
> Oh, yes, of couse:
>
> https://github.com/POV-Ray/povray/releases/tag/v3.7.1-x.dictionary.8790760
>
>
> Future plans:
>
> - Support for an array-like syntax, e.g. `MyFrobnitz["Foo"]` (originally
> intended to be the primary syntax, with the dot notation planned as a
> later syntactic sugar extension, but the parser's internals got in my
> way, so I decided to go for the easier part first)
>
> - Support for initializers (if you have any suggestions for the syntax
> to be used, please let me know)
>


Also, can I have dictionaries inside dictionaries?


Mike


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 16:21:13
Message: <57dda5b9$1@news.povray.org>
Am 17.09.2016 um 20:18 schrieb Mike Horvath:

>> Future plans:
>>
>> - Support for an array-like syntax, e.g. `MyFrobnitz["Foo"]` (originally
>> intended to be the primary syntax, with the dot notation planned as a
>> later syntactic sugar extension, but the parser's internals got in my
>> way, so I decided to go for the easier part first)
>>
>> - Support for initializers (if you have any suggestions for the syntax
>> to be used, please let me know)
>>
> 
> Will there be a shorthand syntax too? Like:
> 
> MyFrobnitz =
> {
>     Foo = 42,
>     Bar = "FTW!"
> }

See the "Support for initializers" future plan.

Currently, I intend to implement the following syntax:

    #declare MyFrobnitz = dictionary {
      .Foo = 42,
      .Bar = "FTW!"
    }

I've come to the conclusion that the leading dots should be mandatory
(at least for now), to avoid potential ambiguities in case a
string-based initialization is also implemented, which /may/ ultimately
be specified to allow the following:

    #declare MyFrobnitz = dictionary {
      "Foo" = 42,
      "Bar" = "FTW!"
    }

Since this would probably not be limited to string literals, but would
allow for arbitary string expressions, this would also allow for:

    #declare FooKey = "Foo";
    #declare BarKey = "Bar";
    #declare MyFrobnitz = dictionary {
      FooKey = 42,
      BarKey = "FTW!"
    }

That would obviously be ambiguous if the identifier-based initializer
syntax wouldn't use leading dots.


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 16:23:46
Message: <57dda652$1@news.povray.org>
Am 17.09.2016 um 21:25 schrieb Mike Horvath:

> Also, can I have dictionaries inside dictionaries?

Absolutely.

You can also have arrays of dictionaries (tested), or dictionaries with
array elements (untested).


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 16:41:51
Message: <57ddaa8f$1@news.povray.org>
Am 17.09.2016 um 21:05 schrieb tth:
> On 09/17/2016 07:11 PM, clipka wrote:
>> #declare MyFrobnitz = dictionary;
>> #declare MyFrobnitz.Foo = 42;
>> #declare MyFrobnitz.Bar = "FTW!";
>>
>> Need I say more?
> 
>   No, it's Ok for me.

But I /will/ say more:

    #declare MyFrobnitz = dictionary {
      .Foo = 42,
    };
    #declare Key = "Bar";
    #declare MyFrobnitz[Key] = "FTW!";

https://github.com/POV-Ray/povray/releases/tag/v3.7.1-x.dictionary.8790989


I love it when a plan comes together.


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 19:15:47
Message: <57ddcea3$1@news.povray.org>
Am 17.09.2016 um 22:41 schrieb clipka:

> I love it when a plan comes together.

Oh, and while I'm at it:

    #declare MyFnord = array { "Element 0", "Element 1" };

    #declare MyFnord[2] = "Element 2";
    #declare MyFnord[3] = "Element 3";
    #declare MyFnord[42] = "Uqbar";

https://github.com/POV-Ray/povray/releases/tag/v3.7.1-x.dictionary.8791118


Sorry, one-dimensional only. Also, it's not designed as a sparse array,
nor a stack, nor a double-ended queue, nor whatever. Just a plain stupid
array that behaves as if it had no upper limit.

Also, there are a few caveats:

- An index larger than the current capacity of the array will /always/
adjust its capacity, even when just testing whether the element has been
set:

    #ifndef (MyFnord[9999999999])
    // Whoops! MyFnord has now grabbed enough memory to
    // accomodate 10000000000 entries.

- The array is a bit greedy, and may grab as much as twice the necessary
size, in order to avoid having to constantly adjust its capacity.

- There is currently no way to shrink the array (aside from copying it
into a new array and throwing away the old one entirely).

- There is currently no way to test whether an array is of the new
dynamic flavour or a plain old one-dimensional fixed-size array.

- I'm still looking for some neat syntax to access the element right
beyond the current size, i.e. some shorthand for:

    MyFnord[dimension_size(MyFnord,0)]


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 22:14:17
Message: <57ddf879$1@news.povray.org>
On 9/17/2016 4:41 PM, clipka wrote:
> But I /will/ say more:
>
>      #declare MyFrobnitz = dictionary {
>        .Foo = 42,
>      };
>      #declare Key = "Bar";
>      #declare MyFrobnitz[Key] = "FTW!";
>

I don't like the dot before the identifier.


Mike


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 23:09:37
Message: <57de0571$1@news.povray.org>
Am 18.09.2016 um 04:14 schrieb Mike Horvath:
> On 9/17/2016 4:41 PM, clipka wrote:
>> But I /will/ say more:
>>
>>      #declare MyFrobnitz = dictionary {
>>        .Foo = 42,
>>      };
>>      #declare Key = "Bar";
>>      #declare MyFrobnitz[Key] = "FTW!";
>>
> 
> I don't like the dot before the identifier.

On a scale from 0 to 10, how much do you not like it?

Also, what alternative would you suggest for the following syntax, and
how would you avoid conflicts between the two initializer syntax variants?

    #declare MyFrobnitz = dictionary {
      "Foo" = 42,
      "Bar" = "FTW!"
    }

Bear in mind that it should be possible to replace the string literals
with arbitrary string expressions, including simple string identifiers.

Also bear in mind that the following syntax variants for individual
element access are to be considered (almost) a given:

    #declare MyFrobnitz.Foo = 42;
    #declare MyFrobnitz["Foo"] = 42;


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 17 Sep 2016 23:45:31
Message: <57de0ddb@news.povray.org>
On 9/17/2016 11:09 PM, clipka wrote:
> Am 18.09.2016 um 04:14 schrieb Mike Horvath:
>> On 9/17/2016 4:41 PM, clipka wrote:
>>> But I /will/ say more:
>>>
>>>       #declare MyFrobnitz = dictionary {
>>>         .Foo = 42,
>>>       };
>>>       #declare Key = "Bar";
>>>       #declare MyFrobnitz[Key] = "FTW!";
>>>
>>
>> I don't like the dot before the identifier.
>
> On a scale from 0 to 10, how much do you not like it?
>
> Also, what alternative would you suggest for the following syntax, and
> how would you avoid conflicts between the two initializer syntax variants?
>
>      #declare MyFrobnitz = dictionary {
>        "Foo" = 42,
>        "Bar" = "FTW!"
>      }
>
> Bear in mind that it should be possible to replace the string literals
> with arbitrary string expressions, including simple string identifiers.
>
> Also bear in mind that the following syntax variants for individual
> element access are to be considered (almost) a given:
>
>      #declare MyFrobnitz.Foo = 42;
>      #declare MyFrobnitz["Foo"] = 42;
>

I don't understand what you're saying. But Lua (sort of) does it like this:

method 1

     #declare MyFrobnitz = dictionary {
       Foo = 42,
       Bar = "FTW!"
     }

method 2

     #declare MyFrobnitz = dictionary {
       ["Foo"] = 42,
       ["Bar"] = "FTW!"
     }

method 3

     #declare Key1 = "Foo";
     #declare Key2 = "Bar";
     #declare MyFrobnitz = dictionary {
       [Key1] = 42,
       [Key2] = "FTW!"
     }


Post a reply to this message

From: tth
Subject: Re: I have a hunch some of you may like this...
Date: 18 Sep 2016 02:35:44
Message: <57de35c0$1@news.povray.org>
On 09/18/2016 01:15 AM, clipka wrote:

> - I'm still looking for some neat syntax to access the element right
> beyond the current size, i.e. some shorthand for:
>
>     MyFnord[dimension_size(MyFnord,0)]

    Some languages use negative indexes for offsetting
    from the end of the array.


Post a reply to this message

From: ingo
Subject: Re: I have a hunch some of you may like this...
Date: 18 Sep 2016 02:56:53
Message: <57de3ab5$1@news.povray.org>
Op 2016-09-17 om 22:23 schreef clipka:
>
> You can also have arrays of dictionaries (tested), or dictionaries with
> array elements (untested).
>
macros functions?

#declare MyD = dictionary {
   .m = #macro Thing(a) Do POV Things #end
   .f = function(C) { prod(i, 1, C, i) }
}

object {
   MyD.m(MyD.f(42))
   }

Ingo


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 18 Sep 2016 03:04:31
Message: <57de3c7f$1@news.povray.org>
Am 18.09.2016 um 08:56 schrieb ingo:
> Op 2016-09-17 om 22:23 schreef clipka:
>>
>> You can also have arrays of dictionaries (tested), or dictionaries with
>> array elements (untested).
>>
> macros functions?

Not yet. Has something to do with the fact that macros are always stored
as global variables.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: I have a hunch some of you may like this...
Date: 28 Sep 2016 17:03:38
Message: <57ec302a$1@news.povray.org>
Nice feature!

Regarding syntax I would recommend not to get carried away
with multiple variants and syntactic sugar, it all has to be
maintained, is source of potential parser bugs, causes confusion
reading code of other people when there is no "right way" (TM).
And someday it might be rewritten completely and it all has to
be backward compatible etc...

So it might be preferrably to define only one "POV" syntax
for single item access and one for initializer list.

Personally I prefer quotes around key like dict["foo"] = 42 to
keep a distinction between identifiers and values. Although I may
be biased towards strictly typed languages, and in scripting a
distinction between structs and dictionaries is less needed.

For the initializer list I must say the mathematician in me
dies when I see something like "Foo" = 42 :)

On the other hand I quite like the perl option "Foo" => 42
which seems to intuitively define some sort of mapping.


Post a reply to this message

From: Jim Holsenback
Subject: Re: I have a hunch some of you may like this...
Date: 28 Sep 2016 19:17:51
Message: <57ec4f9f$1@news.povray.org>
On 9/28/2016 5:03 PM, Christian Froeschlin wrote:
> On the other hand I quite like the perl option "Foo" => 42
> which seems to intuitively define some sort of mapping

2nd that


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 5 Oct 2016 04:28:03
Message: <57f4b993$1@news.povray.org>
On 9/28/2016 5:03 PM, Christian Froeschlin wrote:
> Nice feature!
>
> Regarding syntax I would recommend not to get carried away
> with multiple variants and syntactic sugar, it all has to be
> maintained, is source of potential parser bugs, causes confusion
> reading code of other people when there is no "right way" (TM).
> And someday it might be rewritten completely and it all has to
> be backward compatible etc...
>
> So it might be preferrably to define only one "POV" syntax
> for single item access and one for initializer list.
>
> Personally I prefer quotes around key like dict["foo"] = 42 to
> keep a distinction between identifiers and values. Although I may
> be biased towards strictly typed languages, and in scripting a
> distinction between structs and dictionaries is less needed.
>
> For the initializer list I must say the mathematician in me
> dies when I see something like "Foo" = 42 :)
>
> On the other hand I quite like the perl option "Foo" => 42
> which seems to intuitively define some sort of mapping.
>

But clipka is asking what do you do when Foo is an variable identifier.

For instance these two are different things:

     #declare MyFrobnitz["Foo"] = 42;
     #declare MyFrobnitz[Foo] = 42;

And the shorthand syntax needs to handle this situation equally well.

Mike


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 5 Oct 2016 04:37:11
Message: <57f4bbb7$1@news.povray.org>
On 9/17/2016 11:45 PM, Mike Horvath wrote:
> On 9/17/2016 11:09 PM, clipka wrote:
>> Am 18.09.2016 um 04:14 schrieb Mike Horvath:
>>> On 9/17/2016 4:41 PM, clipka wrote:
>>>> But I /will/ say more:
>>>>
>>>>       #declare MyFrobnitz = dictionary {
>>>>         .Foo = 42,
>>>>       };
>>>>       #declare Key = "Bar";
>>>>       #declare MyFrobnitz[Key] = "FTW!";
>>>>
>>>
>>> I don't like the dot before the identifier.
>>
>> On a scale from 0 to 10, how much do you not like it?
>>
>> Also, what alternative would you suggest for the following syntax, and
>> how would you avoid conflicts between the two initializer syntax
>> variants?
>>
>>      #declare MyFrobnitz = dictionary {
>>        "Foo" = 42,
>>        "Bar" = "FTW!"
>>      }
>>
>> Bear in mind that it should be possible to replace the string literals
>> with arbitrary string expressions, including simple string identifiers.
>>
>> Also bear in mind that the following syntax variants for individual
>> element access are to be considered (almost) a given:
>>
>>      #declare MyFrobnitz.Foo = 42;
>>      #declare MyFrobnitz["Foo"] = 42;
>>
>
> I don't understand what you're saying. But Lua (sort of) does it like this:
>
> method 1
>
>     #declare MyFrobnitz = dictionary {
>       Foo = 42,
>       Bar = "FTW!"
>     }
>
> method 2
>
>     #declare MyFrobnitz = dictionary {
>       ["Foo"] = 42,
>       ["Bar"] = "FTW!"
>     }
>
> method 3
>
>     #declare Key1 = "Foo";
>     #declare Key2 = "Bar";
>     #declare MyFrobnitz = dictionary {
>       [Key1] = 42,
>       [Key2] = "FTW!"
>     }
>

I'm trying to find out if JavaScript does something similar to method 3, 
but I don't think it can.

http://www.w3schools.com/js/js_objects.asp

Mike


Post a reply to this message

From: Mike Horvath
Subject: Re: I have a hunch some of you may like this...
Date: 5 Oct 2016 04:41:24
Message: <57f4bcb4$1@news.povray.org>
On 10/5/2016 4:37 AM, Mike Horvath wrote:
>> I don't understand what you're saying. But Lua (sort of) does it like
>> this:
>>
>> method 1
>>
>>     #declare MyFrobnitz = dictionary {
>>       Foo = 42,
>>       Bar = "FTW!"
>>     }
>>
>> method 2
>>
>>     #declare MyFrobnitz = dictionary {
>>       ["Foo"] = 42,
>>       ["Bar"] = "FTW!"
>>     }
>>
>> method 3
>>
>>     #declare Key1 = "Foo";
>>     #declare Key2 = "Bar";
>>     #declare MyFrobnitz = dictionary {
>>       [Key1] = 42,
>>       [Key2] = "FTW!"
>>     }
>>
>
> I'm trying to find out if JavaScript does something similar to method 3,
> but I don't think it can.
>
> http://www.w3schools.com/js/js_objects.asp
>
> Mike


I take that back. It can and does.

	var textIdentifier = "blah"
	var tableObject =
	{
		[textIdentifier]: "wee"
	}
	alert(tableObject[textIdentifier])

Mike


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 5 Oct 2016 11:42:34
Message: <57f51f6a$1@news.povray.org>
Am 05.10.2016 um 10:41 schrieb Mike Horvath:
> On 10/5/2016 4:37 AM, Mike Horvath wrote:
>>> I don't understand what you're saying. But Lua (sort of) does it like
>>> this:
>>>
>>> method 1
>>>
>>>     #declare MyFrobnitz = dictionary {
>>>       Foo = 42,
>>>       Bar = "FTW!"
>>>     }
>>>
>>> method 2
>>>
>>>     #declare MyFrobnitz = dictionary {
>>>       ["Foo"] = 42,
>>>       ["Bar"] = "FTW!"
>>>     }
>>>
>>> method 3
>>>
>>>     #declare Key1 = "Foo";
>>>     #declare Key2 = "Bar";
>>>     #declare MyFrobnitz = dictionary {
>>>       [Key1] = 42,
>>>       [Key2] = "FTW!"
>>>     }
>>>
>>
>> I'm trying to find out if JavaScript does something similar to method 3,
>> but I don't think it can.
>>
>> http://www.w3schools.com/js/js_objects.asp
>>
>> Mike
> 
> I take that back. It can and does.
> 
>     var textIdentifier = "blah"
>     var tableObject =
>     {
>         [textIdentifier]: "wee"
>     }
>     alert(tableObject[textIdentifier])

... or, alternatively:

    var tableObject =
    {
      "blah": "wee"
    }


Post a reply to this message

From: clipka
Subject: Re: I have a hunch some of you may like this...
Date: 5 Oct 2016 12:07:27
Message: <57f5253f$1@news.povray.org>
Am 05.10.2016 um 17:42 schrieb clipka:

>>> I'm trying to find out if JavaScript does something similar to method 3,
>>> but I don't think it can.
>>>
>>> http://www.w3schools.com/js/js_objects.asp
>>>
>>> Mike
>>
>> I take that back. It can and does.
>>
>>     var textIdentifier = "blah"
>>     var tableObject =
>>     {
>>         [textIdentifier]: "wee"
>>     }
>>     alert(tableObject[textIdentifier])
> 
> .... or, alternatively:
> 
>     var tableObject =
>     {
>       "blah": "wee"
>     }

... not to forget:

    var tableObject =
    {
      blah: "wee"
    }


Post a reply to this message

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