|
|
In article <3ff489d3$1@news.povray.org>,
Florian Brucker <tor### [at] torfboldcom> wrote:
> > I think this should be explained in the documentation if it's not already.
> IMHO an implementation like the documentation is described would be
> better that updating the documentation. I think the current behaviour is
> not at all intuitive and can create errors which are very hard to spot.
> Although I have to admit that I have never encountered this error before :)
It is also very useful. Look at the Isect() and Extents() macros in
shapes.inc, which use this feature to return multiple values.
Things could be clarified quite a bit, though. This is what I would do:
#declare always declares a global variable. Actually, deprecate #declare
and use #global instead. #local always declares a local variable.
If either #declare or #local are used with an existing variable, a
warning is emitted. Existing variables are modified with a #set or #
directive, which require an existing variable:
#local J = 0;
#while(J < 10)
#set J = J + 1;
or
#J = J + 1;
#end
#macro Foo(Param)
#local Param = Param + 1;
#end
Would produce a warning and replace the parameter Param with the local
version, leaving the original unaffected.
#macro Foo(Param)
#declare Param = Param + 1;
#end
Would only produce a warning if a global variable named Param already
existed. It would create that global variable and leave the parameter
unaffected.
#macro Foo(Param)
#set Param = Param + 1;
#end
Would modify the parameter itself.
This also avoids odd typo errors. This code would loop infinitely:
#local I = 0;
#while(I < 10)
#local l = I + 1;
#end
This version would give an immediate error:
#local I = 0;
#while(I < 10)
#set l = I + 1;
#end
The #set keyword is part of the MegaPOV patch collection, but the rest
of it would break backwards compatibility too much to be included.
Unless a new keyword were used for declaring local variables...hmm. How
does this sound?
#declare, #local: obsolete, deprecated, but unchanged in operation for
backwards compatibility.
#global, #def or #define, #set: as described above, with #def declaring
a local variable.
Well, I just wanted to say that the pass by reference is actually a
useful feature...guess I got carried away.
> BTW, any chance the POV-Syntax will be extended with a include-file-wide
> identifier scope? Something like (In an include file):
This already exists: variables defined as #local outside a macro are
local to the include file.
--
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/
Post a reply to this message
|
|