POV-Ray : Newsgroups : povray.general : #local access : Re: #local access Server Time
8 Aug 2024 10:22:10 EDT (-0400)
  Re: #local access  
From: Chris Huff
Date: 2 Mar 2001 16:31:17
Message: <chrishuff-8DA3AF.16293602032001@news.povray.org>
In article <slr### [at] fwicom>, ron### [at] povrayorg 
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] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

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