POV-Ray : Newsgroups : povray.beta-test : I have a hunch some of you may like this... Server Time
16 Apr 2024 15:31:15 EDT (-0400)
  I have a hunch some of you may like this... (Message 11 to 20 of 21)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 1 Messages >>>
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

<<< Previous 10 Messages Goto Latest 10 Messages Next 1 Messages >>>

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