POV-Ray : Newsgroups : povray.beta-test : Syntax extension: Passing multiple values out of a macro Server Time
27 Apr 2024 12:59:03 EDT (-0400)
  Syntax extension: Passing multiple values out of a macro (Message 3 to 12 of 12)  
<<< Previous 2 Messages Goto Initial 10 Messages
From: Warp
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 1 Mar 2015 03:30:04
Message: <54f2ce0c@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
>    #macro WindowFrameAndCutout(Pos,H,W)
>      #local Frame  = union {...};
>      #local Cutout = box {...};
>      (Frame,Cutout,Area)
>    #end

>    #declare (MyFrame,MyCutout) = WindowFrameAndCutout(...);

You are returning three values and assigning them into two identifiers?

-- 
                                                          - Warp


Post a reply to this message

From: clipka
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 1 Mar 2015 13:05:25
Message: <54f354e5$1@news.povray.org>
Am 01.03.2015 um 09:30 schrieb Warp:
> clipka <ano### [at] anonymousorg> wrote:
>>     #macro WindowFrameAndCutout(Pos,H,W)
>>       #local Frame  = union {...};
>>       #local Cutout = box {...};
>>       (Frame,Cutout,Area)
>>     #end
>
>>     #declare (MyFrame,MyCutout) = WindowFrameAndCutout(...);
>
> You are returning three values and assigning them into two identifiers?

Whoops :) - that should have been:

     #declare (MyFrame,MyCutout,MyArea) = WindowFrameAndCutout(...);


Post a reply to this message

From: clipka
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 1 Mar 2015 13:12:38
Message: <54f35696@news.povray.org>
Am 01.03.2015 um 09:27 schrieb Thomas de Groot:
> On 1-3-2015 2:51, clipka wrote:
>> I've just implemented a syntax extension that you might like: As of the
>> newest development version, you'll now be able to assign multiple
>> variables with a single #declare (or #local) statement, like so:
>>
>>    #declare (A,B,C) = (X,Y,Z);
>>
>> Obviously, this now allows for a single macro to return multiple items,
>> like this:

Sorry, forgot some part of the code (I guess I was a bit tired):

>>
>>    #macro WindowFrameAndCutout(Pos,H,W)
>>      #local Frame  = union {...};
>>      #local Cutout = box {...};
         #local Area   = H*W;
>>      (Frame,Cutout,Area)
>>    #end
>>
>>    #declare (MyFrame,MyCutout) = WindowFrameAndCutout(...);
       #declare (MyFrame,MyCutout,MyArea) = ...
>>
>> How's that? :D
>
> Probably neat, but I confess I do not really understand the example and
> what it does...

Suppose you have a set of macros to generate architecture; in such a 
framework, for windows you'll want both the windows itself, as well as a 
shape to cut a matching hole into the wall. And for some reason you 
might also be interested in knowing the area of the window, though I 
confess I just put it in there just to demonstrate that you can return 
values of different types.


Post a reply to this message

From: Mr
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 2 Mar 2015 09:50:01
Message: <web.54f47877c9a0646a16086ed00@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 01.03.2015 um 09:27 schrieb Thomas de Groot:
> > On 1-3-2015 2:51, clipka wrote:
> >> I've just implemented a syntax extension that you might like: As of the
> >> newest development version, you'll now be able to assign multiple
> >> variables with a single #declare (or #local) statement, like so:
> >>
> >>    #declare (A,B,C) = (X,Y,Z);
> >>
> >> Obviously, this now allows for a single macro to return multiple items,
> >> like this:
>
> Sorry, forgot some part of the code (I guess I was a bit tired):
>
> >>
> >>    #macro WindowFrameAndCutout(Pos,H,W)
> >>      #local Frame  = union {...};
> >>      #local Cutout = box {...};
>          #local Area   = H*W;
> >>      (Frame,Cutout,Area)
> >>    #end
> >>
> >>    #declare (MyFrame,MyCutout) = WindowFrameAndCutout(...);
>        #declare (MyFrame,MyCutout,MyArea) = ...
> >>
> >> How's that? :D
> >
> > Probably neat, but I confess I do not really understand the example and
> > what it does...
>
> Suppose you have a set of macros to generate architecture; in such a
> framework, for windows you'll want both the windows itself, as well as a
> shape to cut a matching hole into the wall. And for some reason you
> might also be interested in knowing the area of the window, though I
> confess I just put it in there just to demonstrate that you can return
> values of different types.


I like it. It looks like some Python feature was it an inspiration?


Post a reply to this message

From: clipka
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 2 Mar 2015 10:12:42
Message: <54f47dea$1@news.povray.org>
Am 02.03.2015 um 15:49 schrieb Mr:
> I like it. It looks like some Python feature was it an inspiration?

No, just general tuple-ish syntax.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 3 Mar 2015 03:07:22
Message: <54f56bba$1@news.povray.org>
On 1-3-2015 19:12, clipka wrote:

> Suppose you have a set of macros to generate architecture; in such a
> framework, for windows you'll want both the windows itself, as well as a
> shape to cut a matching hole into the wall. And for some reason you
> might also be interested in knowing the area of the window, though I
> confess I just put it in there just to demonstrate that you can return
> values of different types.
>
Yes, I understand the principle but - as is always the case with my slow 
brain - I shall need to play with it in order to fully understand the 
potentials :-)

-- 
Thomas


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 16 Mar 2015 00:00:01
Message: <web.55065426c9a0646ac90a82220@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> I've just implemented a syntax extension that you might like: As of the
> newest development version, you'll now be able to assign multiple
> variables with a single #declare (or #local) statement, like so:
>
>    #declare (A,B,C) = (X,Y,Z);
>
> Obviously, this now allows for a single macro to return multiple items,
> like this:
>
>    #macro WindowFrameAndCutout(Pos,H,W)
>      #local Frame  = union {...};
>      #local Cutout = box {...};
>      (Frame,Cutout,Area)
>    #end
>
>    #declare (MyFrame,MyCutout) = WindowFrameAndCutout(...);
>
> How's that? :D

That's great !

=)

I really hope that it also works with functions, arrays, transforms, vectors,
cameras, light sources, materials etc. I.e. everything that be stored in a
variable.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: clipka
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 16 Mar 2015 00:31:20
Message: <55065c98$1@news.povray.org>
Am 16.03.2015 um 04:55 schrieb Tor Olav Kristensen:

> I really hope that it also works with functions, arrays, transforms, vectors,
> cameras, light sources, materials etc. I.e. everything that be stored in a
> variable.

I wouldn't dare to raise my head with this otherwise :) (I haven't 
tested most of them, but the implementation is simple enough to be 
confident about it.)


Post a reply to this message

From: Mike Horvath
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 17 Jan 2016 19:15:55
Message: <569c2ebb$1@news.povray.org>
On 2/28/2015 8:51 PM, clipka wrote:
> I've just implemented a syntax extension that you might like: As of the
> newest development version, you'll now be able to assign multiple
> variables with a single #declare (or #local) statement, like so:
>
>    #declare (A,B,C) = (X,Y,Z);
>
> Obviously, this now allows for a single macro to return multiple items,
> like this:
>
>    #macro WindowFrameAndCutout(Pos,H,W)
>      #local Frame  = union {...};
>      #local Cutout = box {...};
>      (Frame,Cutout,Area)
>    #end
>
>    #declare (MyFrame,MyCutout) = WindowFrameAndCutout(...);
>
> How's that? :D

I don't think you should use parentheses. A comma between each parameter 
should suffice.

For instance in Lua you can do

a, b = 10, 2*x

Parentheses makes it look like a macro, which is confusing.


Post a reply to this message

From: clipka
Subject: Re: Syntax extension: Passing multiple values out of a macro
Date: 18 Jan 2016 00:01:14
Message: <569c719a$1@news.povray.org>
Am 18.01.2016 um 01:16 schrieb Mike Horvath:
> On 2/28/2015 8:51 PM, clipka wrote:
>> I've just implemented a syntax extension that you might like: As of the
>> newest development version, you'll now be able to assign multiple
>> variables with a single #declare (or #local) statement, like so:
>>
>>    #declare (A,B,C) = (X,Y,Z);
...
> 
> I don't think you should use parentheses. A comma between each parameter
> should suffice.
> 
> For instance in Lua you can do
> 
> a, b = 10, 2*x

Thanks for bringing this up in such a timely fashion ;)

> Parentheses makes it look like a macro, which is confusing.

I don't think it looks like a macro, and I don't think it is confusing.

Furthermore, I think this makes it more consistent with the later
additions of using it for array and vector assignments, which use
delimiters as well:

    #declare (A,B,C) = (X,Y,Z);
    #declare <A,B,C> = MyVector;
    #declare {A,B,C} = MyArray;

Also, if you want to influence POV-Ray's syntax towards more beauty,
you're more than just 3/4 of a year late -- about two decades or so I'd
guess.

As a matter of fact, I for one actually /prefer/ the parenthesized
version, because it makes it much easier to see at a glance that there's
something more going on than just ordinary single assignment.


And, last not least, as a less aesthetical and more practical reason to
keep it this way: The above is how I implemented it; it appears to works
fine; it doesn't look /too/ bad (to me at least, and apparently to all
others who have read the post in the last 9 months); and changing it
will cost me another round tuit or two (especially since I've piled a
bit more syntactic sugar on top of it by now, which btw also appears to
work fine and isn't too shabby), which I'm short of these days anyway.
So even if I were inclined to agree, it would rank way, way low on my
list of pending changes.

I rest my case.


Post a reply to this message

<<< Previous 2 Messages Goto Initial 10 Messages

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