POV-Ray : Newsgroups : povray.general : Is this a bug, or am I missing something? Server Time
6 Aug 2024 14:23:40 EDT (-0400)
  Is this a bug, or am I missing something? (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
From:
Subject: Re: Is this a bug, or am I missing something?
Date: 3 Apr 2002 13:45:07
Message: <r3jmaug0ok9849fkh21tqjh6uruh8j1i21@4ax.com>
On Wed, 3 Apr 2002 12:36:22 -0600, "Shay" <sah### [at] simcopartscom> wrote:
> > Perhaps this is an intended feature.
>
> yep!
> (docs) 6.2.8.5  Returning Values Via Parameters
> Sorry for the waste of time.

I'm not so sure it was wasting. Note 6.2.8.5 shows only #declare as example. In
6.2.2.2 there is a general rule described (or at least it is my interpretation)
that #local not influences identifiers outside of macro.

ABX


Post a reply to this message

From:
Subject: Re: Is this a bug, or am I missing something?
Date: 3 Apr 2002 13:55:42
Message: <aqjmau8t4glrdm5o0odd5b9ml86b2ev6ig@4ax.com>

wrote:
> I'm not so sure it was wasting. Note 6.2.8.5 shows only #declare as example. In
> 6.2.2.2 there is a general rule described (or at least it is my interpretation)
> that #local not influences identifiers outside of macro.

Moreover this identifier is a local becouse I can undefine it. Undefining causes
remove of value so why this value appear outside ?

#macro Do(A)
  #local A=concat(A,"S");
  #undef A
#end

#declare C="A";
Do(C)
#warning C

If such (imo strange) behaviour is part of design I think it should be better
documented.

ABX


Post a reply to this message

From: Warp
Subject: Re: Is this a bug, or am I missing something?
Date: 3 Apr 2002 14:30:36
Message: <3cab585b@news.povray.org>
Shay <sah### [at] simcopartscom> wrote:
> #macro Persistence_Of_Dimension (ARRAY)
>  #local Array_Size = dimension_size (ARRAY, 1) + 1;
>  #local ARRAY = array[Array_Size]

>  #write (Test_Out, Array_Size, "\n")
> #end // #macro Persistence_Of_Dimension (ARRAY)

  You are modifyind the size of the array given as parameter.
  That's the designed behaviour. (Note that I used the word "designed",
not "correct".)

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Is this a bug, or am I missing something?
Date: 3 Apr 2002 14:32:40
Message: <3cab58d8@news.povray.org>

> I'm not so sure it was wasting. Note 6.2.8.5 shows only #declare as example. In
> 6.2.2.2 there is a general rule described (or at least it is my interpretation)
> that #local not influences identifiers outside of macro.

  But you are modifying the external identifier with the #local command
because you are modifying the given parameter.
  The paramters to a macro are passed by reference, not by value.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From:
Subject: Re: Is this a bug, or am I missing something?
Date: 3 Apr 2002 14:39:59
Message: <uemmauca47t09qc6u28rjptcm9b745d84p@4ax.com>
On 3 Apr 2002 14:32:40 -0500, Warp <war### [at] tagpovrayorg> wrote:
>  The paramters to a macro are passed by reference, not by value.

I said it at first post in this thread. Hovewer this could be described somehow
in documentation.

ABX
--
disc{z,-z#macro O()asc(substr("-+((1*(,1,/.-,*/(,&.323/'1"e,1))*.1-4#declare
e=e-1;#end#local e=26;5pigment{#local g=function(_){ceil(_)-_}function#local
k=function{pattern{object{sphere_sweep{linear_spline 13#while(e)<O(),O()//35
>.01#end}}}}{k(g(atan2(x,y)),g(ln((y+x)^2+1e-5)),0)}}finish{ambient 1}}//ABX


Post a reply to this message

From: Tom Melly
Subject: Re: Is this a bug, or am I missing something?
Date: 4 Apr 2002 07:51:20
Message: <3cac4c48@news.povray.org>

news:uemmauca47t09qc6u28rjptcm9b745d84p@4ax.com...
> On 3 Apr 2002 14:32:40 -0500, Warp <war### [at] tagpovrayorg> wrote:
> >  The paramters to a macro are passed by reference, not by value.
>
> I said it at first post in this thread. Hovewer this could be described
somehow
> in documentation.
>

Wow - I never knew that. Might explain a lot.


Post a reply to this message

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>

news:tgemaugb05ng3mdc4i9801ihtlrrc4ogr3@4ax.com...
> On Wed, 3 Apr 2002 11:13:42 -0600, "Shay" <sah### [at] simcopartscom> 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

From:
Subject: Re: Is this a bug, or am I missing something?
Date: 4 Apr 2002 12:44:34
Message: <b64paug8mgl8kmn5uar38jgoi6hoh9ourl@4ax.com>
On Thu, 4 Apr 2002 09:38:36 -0800, "Ben Chambers" <bdc### [at] yahoocom>
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

From: Ron Parker
Subject: Re: Is this a bug, or am I missing something?
Date: 12 Apr 2002 17:03:14
Message: <slrnabeisk.jg3.ron.parker@fwi.com>
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

From: Christopher James Huff
Subject: Re: Is this a bug, or am I missing something?
Date: 12 Apr 2002 17:45:16
Message: <chrishuff-A4AC49.17470712042002@netplex.aussie.org>
In article <slr### [at] fwicom>,
 Ron Parker <ron### [at] povrayorg> 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] maccom>
POV-Ray TAG e-mail: chr### [at] tagpovrayorg
TAG web site: http://tag.povray.org/


Post a reply to this message

<<< Previous 4 Messages Goto Initial 10 Messages

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