POV-Ray : Newsgroups : povray.beta-test : I have a hunch some of you may like this... Server Time
22 Dec 2024 09:33:58 EST (-0500)
  I have a hunch some of you may like this... (Message 1 to 10 of 21)  
Goto Latest 10 Messages Next 10 Messages >>>
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

Goto Latest 10 Messages Next 10 Messages >>>

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