POV-Ray : Newsgroups : povray.general : Is this a bug, or am I missing something? : Re: Is this a bug, or am I missing something? Server Time
6 Aug 2024 17:01:20 EDT (-0400)
  Re: Is this a bug, or am I missing something?  
From: Ron Parker
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

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