![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Ben Chambers
Subject: Re: Is this a bug, or am I missing something?
Date: 4 Apr 2002 12:38:18
Message: <3cac8f8a@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
news:tgemaugb05ng3mdc4i9801ihtlrrc4ogr3@4ax.com...
> On Wed, 3 Apr 2002 11:13:42 -0600, "Shay" <sah### [at] simcoparts com> wrote:
> > I will post this in bug-reports if it turns out to be a bug, but I often
> > miss obvious things when looking at my own code.
>
> I was noticed similiar thing just yesterday and wondered what to do with
that.
> Looks like #local works as #declare for references (instead of value) as
> parameter. For example
Doesn't #local limit the scope to the file, and not the macro? Or did I
misunderstand?
...Chambers
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.323 / Virus Database: 180 - Release Date: 2/8/2002
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Thu, 4 Apr 2002 09:38:36 -0800, "Ben Chambers" <bdc### [at] yahoo com>
wrote:
> Doesn't #local limit the scope to the file, and not the macro? Or did I
> misunderstand?
http://www.povray.org/working-docs/id000147.html#6_2_2_2
ABX
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 3 Apr 2002 14:32:40 -0500, Warp wrote:
> The paramters to a macro are passed by reference, not by value.
That's not entirely true.
#macro F(A)
...
#end
#declare B=5;
F(B) // passes by reference
F(5) // passes by value
The difference is precisely this: if the macro invocation uses an indentifier,
it is passed by reference. If it uses an expression or object {} block or
something else, it is passed by value (well, not exactly, but let's pretend.)
Parameter names are local to the macro. They are defined in the macro
invocation's local symbol table and are thus local. When the tokenizer
sees a parameter that also happens to be a reference, it replaces it
directly by the symbol to which it refers in some higher-level symbol
table (not necessarily the global symbol table.) However, since it found
the original reference in the local symbol table, #local does not try to
create a new variable.
You could argue either way as to how this should work. Personally, I think
I'd be in favor of #local severing the 'reference' link, but that would
require a bit of nasty code in some unlikely places.
--
#local R=rgb 99;#local P=R-R;#local F=pigment{gradient x}box{0,1pigment{gradient
y pigment_map{[.5F pigment_map{[.3R][.3F color_map{[.15red 99][.15P]}rotate z*45
translate x]}]#local H=pigment{gradient y color_map{[.5P][.5R]}scale 1/3}[.5F
pigment_map{[.3R][.3H][.7H][.7R]}]}}}camera{location.5-3*z}//only my opinions
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
In article <slr### [at] fwi com>,
Ron Parker <ron### [at] povray org> wrote:
> You could argue either way as to how this should work. Personally, I think
> I'd be in favor of #local severing the 'reference' link, but that would
> require a bit of nasty code in some unlikely places.
I'd like it if there were separate keywords for making new variables and
modifying old ones:
#local always creates a local variable. If one with the same name
exists, it is destroyed and replaced. The original variable of a
parameter passed by reference will be untouched.
#declare creates a global variable, otherwise same rules as above. Maybe
change name to #global.
Add a new #set directive for modifying existing variables. If the
variable doesn't already exist, an error results. This would also avoid
situations like:
#local MyCounter = 0;
#while(MyCounter < 10)
...
#local myCounter = MyCounter + 1;
#end
Oops...a little typo makes an infinite loop. With #set:
#local MyCounter = 0;
#while(MyCounter < 10)
...
#set myCounter = MyCounter + 1;
#end
You get something like:
Error: attempt to #set non-existent variable "myCounter"
The #set directive is already partially implemented as a patch, though
it doesn't work perfectly yet. To do all of this would probably require
reworking large chunks of the parser, probably better to just start over
from scratch.
--
Christopher James Huff <chr### [at] mac com>
POV-Ray TAG e-mail: chr### [at] tag povray org
TAG web site: http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |