POV-Ray : Newsgroups : povray.general : Function: Problem in Defining : Re: Function: Problem in Defining Server Time
3 May 2024 15:31:42 EDT (-0400)
  Re: Function: Problem in Defining  
From: clipka
Date: 6 Apr 2018 12:06:45
Message: <5ac79b15$1@news.povray.org>
Am 06.04.2018 um 03:02 schrieb dick balaska:
> On 04/05/2018 12:21 PM, clipka wrote:
> 
>>      #declare MySeed = seed(4711);
>>      #macro MyRand(Min,Max)
>>        // compute stuff
>>        #local Rand = rand(MySeed);
>>        #local Result = Min + (Max-Min)*Rand;
>>        // "return" the computed value
>>        Result
>>      #end
>>
> 
> I wrap the return value in parenthesis. The intent is a little clearer
> in the macro def and may avoid usage problems.
> 
>     // "return" the computed value
>     (Result)

You run into problems with this approach if you ever want to return
something that isn't a scalar or vector. For instance, the following
won't fly:

    #macro FullName(FileName)
      #local Result = concat("C:/Fnord/", FileName);
      (Result)
    #end

    #include FullName("stuff.inc")


> I know clipka, legally this is not required, because Result is a single
> number. But I tend to do
> 
>     #local V=<1,2,3>;
>     // "return" the computed value
>     (Result+V)
> 
> where it is morally (debuggingly?) required.

Then maybe don't do that ;)

I really literally use `Result` as the local variable name, and make
sure to always store the very end result in there, for the same purpose
that you use the parentheses. That way

    Result

is guaranteed to be the only thing the macro "emits". Solves the same
problem as your parentheses, but has the added benefit of working in
more scenarios.


Post a reply to this message

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