POV-Ray : Newsgroups : povray.bugreports : local in macro Server Time: 29 Jan 2020 15:20:15 GMT
  local in macro (Message 1 to 3 of 3)  
From: jr
Subject: local in macro
Date: 28 Nov 2019 12:25:01
Message: <web.5ddfbbcda28041b5feeb22ff0@news.povray.org>
hi,

upgraded from alpha.9945627 because I ran into a problem, to alpha.10064268, but
no change.

reading section 3.3.2.2.2 "declare vs local", it says if "#local is used inside
a #macro then the identifier is local to that macro.  When the macro is invoked
and the #local directive is parsed, the identifier is created."

maybe I misread this, but the macro parameter appears to just work as an
input/output.  the following test scene .. misbehaves on both versions:

-----<snip>-----
#version 3.8;

global_settings {assumed_gamma 1}

#macro Decr(n_)
  #if (1 <= n_)
    #local n_ = n_ - 1;
  #end
  #debug concat("local n_ = ",str(n_,0,0),"\n")
#end


#if (1)
#for (i_,0,3)
  Decr(i_)
  #debug concat("loop i_ = ",str(i_,0,0),"\n")
#end
#end


#if (0)
#declare i_ = 0;
#while (4 > i_)
  Decr(i_)
  #debug concat("loop i_ = ",str(i_,0,0),"\n")
  #declare i_ = i_ + 1;
#end
#end
-----<snip>-----


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: local in macro
Date: 28 Nov 2019 15:25:01
Message: <web.5ddfe6578fffca174eec112d0@news.povray.org>
> #version 3.8;
>
> global_settings {assumed_gamma 1}
>
> #macro Decr(n_)
>   #if (1 <= n_)
>     #local n_ = n_ - 1;
>   #end
>   #debug concat("local n_ = ",str(n_,0,0),"\n")
> #end
>
>
> #if (1)
> #for (i_,0,3)
>   Decr(i_)
>   #debug concat("loop i_ = ",str(i_,0,0),"\n")
> #end
> #end
>
>
> #if (0)
> #declare i_ = 0;
> #while (4 > i_)
>   Decr(i_)
>   #debug concat("loop i_ = ",str(i_,0,0),"\n")
>   #declare i_ = i_ + 1;
> #end
> #end

Not sure exactly what you're trying to do here, but try this and see if this
helps explain anything.   I think Kenneth had some issues with this sort of
thing too a while back.

#version 3.8;

global_settings {assumed_gamma 1}

#declare Bailout = 0;
#declare Bailoutmax = 10;

#macro Decr (n_)
 #debug concat("starting macro with n_ = ",str(n_,0,0),"\n")
 #if (n_ >= 1)
  #local n_ = n_ - 1;
 #end


 #if (Bailout = Bailoutmax)
  #error "Stopping code - Bailout has reached max"
 #end

 #debug concat("     exiting macro with n_ = ",str(n_,0,0),"\n")
 n_

#end


#if (1)
 #declare Counter = 10;
 #for (i_, 0, 3)
  #declare Counter = Decr (Counter);
  #declare Bailout = Bailout + 1;

 #end
#end


#if (0)
 #declare i_ = 0;
 #while (i_ < 4)
  #declare i_ = Decr (i_);
  #debug concat("while loop i_ = ",str(i_,0,0),"\n")
  #declare Bailout = Bailout + 1;
  #declare i_ = i_ + 1;
 #end
#end

#error "stop render"


Post a reply to this message

From: jr
Subject: Re: local in macro
Date: 28 Nov 2019 19:15:01
Message: <web.5de01c568fffca17feeb22ff0@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> > ...
> Not sure exactly what you're trying to do here, but try this and see if this
> helps explain anything.   I think Kenneth had some issues with this sort of
> thing too a while back.
> ...

my work-around for the issue will be (from now) to treat macro parameters as
read only.  confused by the documentation, I guess.  reading through the
language directives stuff (local vs declare, macros) I expect the local variable
('n_') to genuinely be local since the reassignment is a '#local' construct, but
it seems that it remains linked "by reference" regardless.  anyway, thanks for
the thought.


regards, jr.


Post a reply to this message

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