POV-Ray : Newsgroups : povray.general : #local access : Re: #local access Server Time
8 Aug 2024 04:12:47 EDT (-0400)
  Re: #local access  
From: Rune
Date: 2 Mar 2001 12:15:04
Message: <3a9fd518@news.povray.org>
"Ron Parker" wrote:
> It seems intuitive to me: if you use #declare to modify a variable,
> you're guaranteed to modify the variable that you would have seen
> when you interrogated it.
> Wouldn't it suck to do it otherwise if you had something like this?
>
> #macro ForceVarInBounds()
>   #ifdef(Var)
>     #if (Var < 0) #declare Var=0; #end
>     #if (Var > 255) #declare Var=255; #end
>   #end // ifdef
> #end // macro
>
> #macro DoStuff() {
>   #local Var=SomeFunction();
>   ForceVarInBounds()
>   DoSomethingCriticalWithVar()
> #end // macro

Exactly!

That's basically what I needed to do, and I was very pleased to find out
that it could be done in an easy manner. I personally find it intuitive too.

> That's the way it's always been, and it's documented behavior.

I see now that the rules you stated are taken right out of the documentation
in the section "Identifier name collisions". I should reread the whole
documentation once in a while...

I did found a bug though. In the documentation this is stated:

> Suppose inside myinc.inc you do...
>
>  #local D = 789;
>
> If you are inside myinc.inc and you want to increment D by
> one, you might try to do...
>
>  #local D = D + 1;
>
> but if you try to do that inside MyMacro you'll create a new
> D which is local to MyMacro and not the D which is external
> to MyMacro but local to myinc.inc.

POV-Ray does not work as the documentation states. It works like this:

> (...)
> but if you try to do that inside MyMacro you'll get the error
> message "Cannot assign uninitialized identifier".

Whether this is a bug in POV-Ray or in the documentation I will let others
decide.

I personally think that POV-Ray should keep its current functionality since
it prevents the user from making stupid mistakes based on misconceptions,
such as the example in the documentation.

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 28)
/ Also visit http://www.povrayusers.org


Post a reply to this message

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