|  |  | In article <slr### [at] fwi com>, ron### [at] povray  org 
wrote:
Well, that macro would have been written as this, when using my idea:
#macro ForceVarInBounds()
    #ifdef(Var)
        #if (Var < 0) #set Var=0; #end
        #if (Var > 255) #set Var=255; #end
    #end // ifdef
#end // macro
Or even better:
#macro ForceVarInBounds(Var, Min, Max)
    #if (Var < Min) #set Var=Min; #end
    #if (Var > Max) #set Var=Max; #end
#end // macro
I don't see the problem...
> #macro DoStuff() {
>   #local Var=SomeFunction();
>   ForceVarInBounds()
>   DoSomethingCriticalWithVar()
> #end // macro
> 
> Oops... The ForceVarInBounds macro didn't do what you thought it would.
I wouldn't write code like that, unless I wanted a global version of 
"Var"...the #set versions would look for a global variable named "Var" 
or take a specific variable and modify it, no matter what it's name is.
I still do not think a macro should be able to modify local variables 
outside it unless they are passed in as a parameter or are simply at a 
higher level (#local variables of the include file the macro is in, for 
example. *Not* #local variables of macros that call the macro.). Of what 
use is this behavior?
It just doesn't seem like a good idea for "#declare SomeVar = ..." to 
behave differently depending on whether SomeVar already exists and 
whether it is local.
> It doesn't seem less confusing to me.  If you implement it, I forsee lots 
> of
> #ifdef (foo)
>   #set foo = SomeComplicatedMacro();
> #else
>   #declare foo = SomeComplicatedMacro();
> #end
Why? That code would modify foo if it exists already, and otherwise 
create a global variable named foo. What's confusing about that?
-- 
Christopher James Huff
Personal: chr### [at] mac  com, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tag  povray  org, http://tag.povray.org/
<>< Post a reply to this message
 |  |