POV-Ray : Newsgroups : povray.advanced-users : Returning values through macro parameters Server Time
29 Jul 2024 04:21:44 EDT (-0400)
  Returning values through macro parameters (Message 1 to 2 of 2)  
From: Andrew Coppin
Subject: Returning values through macro parameters
Date: 9 Mar 2003 16:12:41
Message: <3e6bae49@news.povray.org>
Returning a value through a macro parameter isn't something I've ever done
before. Supposing I have a macro like this:

#macro Thingy(alpha, beta)

how do I change the value of, say, beta so that it's accessible form
outside? Do I use #declare or #local? Does it matter? The manual seems to
imply I should use #declare (I think!) I'm a bit confused...

...

Wouldn't it be better if (uh-oh, here we go! ;-) we did something like:

#global A = 7; // Create new global variable (or error if it already exists)
#local A = 5; // Create new local variable (hide any pre-existing global or
local; error if already exists at this scope level).
#update A = 3; // Change the value of the most local defininition (or error
if none exists).

This syntax means you can clearly tell POV-Ray what you're trying to do, and
so POV-Ray can tell you if what you've asked for is impossible. (For
example, it would be very useful to know that you have two include files
which BOTH try to store information in a global variable, and so are
interfering with each other. At present, POV-Ray can't tell if #global means
"hey POV, replace this existing value..." or "hey POV, make me a new
variable!" If it knew that you meant the latter, it could warn you of your
mistake.)

Personally I think this might be less confusing. (I fully except someone
will shortly post a lengthy irate message explaining exactly why this ISN'T
a good idea, but hey, the suggestion is only my humble opinion.) But then,
maybe I just don't understand how POV-Ray does it now...

Thanks.
Andrew.


Post a reply to this message

From: Mark Wagner
Subject: Re: Returning values through macro parameters
Date: 9 Mar 2003 23:28:15
Message: <pan.2003.03.10.04.26.51.541436.264@gte.net>
On Sun, 09 Mar 2003 05:15:02 -0500, Andrew Coppin quoth:

> Returning a value through a macro parameter isn't something I've ever
> done before. Supposing I have a macro like this:
> 
> #macro Thingy(alpha, beta)
> 
> how do I change the value of, say, beta so that it's accessible form
> outside? Do I use #declare or #local? Does it matter? The manual seems
> to imply I should use #declare (I think!) I'm a bit confused...

It's a little complicated, since it depends on how you call the macro
rather than how you write the macro.  You need to pass a declared variable
to the macro rather than a number or expression.

#macro Thingy(alpha, beta)
    #local alpha = 3;
#end

#declare A = 1;
Thingy(A, 7) /* This will change the value of A to 3 */
Thingy(A+1, 7) /* This will not change the value of A */

-- 
Mark


Post a reply to this message

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