POV-Ray : Newsgroups : povray.general : #macro question Server Time
7 Aug 2024 11:20:13 EDT (-0400)
  #macro question (Message 1 to 9 of 9)  
From: Kevin Loney
Subject: #macro question
Date: 11 Oct 2001 00:32:33
Message: <3bc520e1@news.povray.org>
two things, is it possible to return a 2 dimensional array from macro, and
then assign it to another matrix? povray won't let me do this and I'm not
sure if there is a way to do it. there is nothing on it in the docs.

eg.
currentPositions = evaluateInitialPositions( lengthSegs, widthSegs, clothL,
clothW, randomness )

currentPositions and the value returned from evaluateInitialPositions both
have the same dimensions

second question, is there anyway to set up a refernece parameter in a macro?
for example in c++ you add an ampersand(&) infront of the variable in the
function definition

thanks in advance

--
Kevin
http://www.geocities.com/qsquared_1999/


Post a reply to this message

From: Mike Williams
Subject: Re: #macro question
Date: 11 Oct 2001 02:21:12
Message: <pBtRtOA0mTx7EwoG@econym.demon.co.uk>
Wasn't it Kevin Loney who wrote:
>two things, is it possible to return a 2 dimensional array from macro, and
>then assign it to another matrix? povray won't let me do this and I'm not
>sure if there is a way to do it. there is nothing on it in the docs.
>
>eg.
>currentPositions = evaluateInitialPositions( lengthSegs, widthSegs, clothL,
>clothW, randomness )
>
>currentPositions and the value returned from evaluateInitialPositions both
>have the same dimensions

I think your problem lies in the fact that you expect a macro to
*return* something (like a function in C++). In POV code, a macro
doesn't return anything it just *is* something.

The following code works.

#macro Fred(A,B)
   array[2][2]{{0,A},{2,B}}
#end

#declare Jim = Fred(1,3)

You don't need to pre-declare Jim as a 2d array. It even works if you
had previously declared Jim to be a completely different data type.

Another way of thinking about what POV macros return would be to
consider that Fred(1,3) doesn't return an array, it returns the *text*
"array[2][2]{{0,1}{2,3}}", which then gets parsed as if you had typed
"#declare Jim = array[2][2]{{0,1}{2,3}}". This is very different from
what happens in C++ function.

>second question, is there anyway to set up a refernece parameter in a macro?
>for example in c++ you add an ampersand(&) infront of the variable in the
>function definition

I reckon that such a concept is meaningless in the context of POV
macros.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Warp
Subject: Re: #macro question
Date: 11 Oct 2001 05:39:42
Message: <3bc568dd@news.povray.org>
Mike Williams <mik### [at] nospamplease> wrote:
: Another way of thinking about what POV macros return would be to
: consider that Fred(1,3) doesn't return an array, it returns the *text*

  This is not the whole story. #local declarations are not seen outside the
macro, although the value of a locally declared identifier can be passed
outside the macro.
  This example shows how this #local behaviour is seen in practice:

#macro MyMacro()
  #local MyVar = 5;
#end

#declare MyVar = 2;
MyMacro()
#debug str(MyVar,0,0) // 'MyVar' is still 2 here!

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


Post a reply to this message

From: Warp
Subject: Re: #macro question
Date: 11 Oct 2001 05:40:58
Message: <3bc56929@news.povray.org>
Kevin Loney <klo### [at] pt2mcom> wrote:
: second question, is there anyway to set up a refernece parameter in a macro?

  For what purpose?

  (Macros are not functions, so parameters are not passed by value anyways...)

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


Post a reply to this message

From: Ron Parker
Subject: Re: #macro question
Date: 11 Oct 2001 09:10:26
Message: <slrn9sb6i3.chi.ron.parker@fwi.com>
On 11 Oct 2001 05:39:42 -0400, Warp wrote:
>macro, although the value of a locally declared identifier can be passed
>outside the macro.

With care.  POV 3.5 has at least one bug with this, and I suspect it existed
in POV 3.1 as well.

-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end 
Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}


Post a reply to this message

From: Ron Parker
Subject: Re: #macro question
Date: 11 Oct 2001 09:20:13
Message: <slrn9sb74e.chi.ron.parker@fwi.com>
On 11 Oct 2001 05:40:58 -0400, Warp wrote:
>Kevin Loney <klo### [at] pt2mcom> wrote:
>: second question, is there anyway to set up a refernece parameter in a macro?
>
>  For what purpose?
>
>  (Macros are not functions, so parameters are not passed by value anyways...)

Well, they are and they aren't.  Parameters are references unless they can't
be a reference.  This:

#macro Foo(A)
  #declare A=5;
#end

#declare B=10;
#declare C=20;
Foo(B);
Foo(0+C);

leads to two different results.  B gets set to 5, but C gets left alone, 
because "B" can be passed as a reference but the expression "0+C" can't.

-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end 
Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}


Post a reply to this message

From: Warp
Subject: Re: #macro question
Date: 11 Oct 2001 11:18:06
Message: <3bc5b82e@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: Foo(0+C);

: leads to two different results.  B gets set to 5, but C gets left alone, 
: because "B" can be passed as a reference but the expression "0+C" can't.

  As a programmer I would interpret that in the way that a temporary
indentifier is created in order to hold the result of "0+C", and a reference
to this temporary identifier is passed to the macro. After the macro call
ends, this temporary identifier is destroyed.
  So macros always take "references", but you should know when temporary
identifiers are created in order to avoid mistakes.

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


Post a reply to this message

From: Ron Parker
Subject: Re: #macro question
Date: 11 Oct 2001 11:23:30
Message: <slrn9sbebk.cj4.ron.parker@fwi.com>
On 11 Oct 2001 11:18:06 -0400, Warp wrote:
>Ron Parker <ron### [at] povrayorg> wrote:
>: Foo(0+C);
>
>: leads to two different results.  B gets set to 5, but C gets left alone, 
>: because "B" can be passed as a reference but the expression "0+C" can't.
>
>  As a programmer I would interpret that in the way that a temporary
>indentifier is created in order to hold the result of "0+C", and a reference
>to this temporary identifier is passed to the macro. After the macro call
>ends, this temporary identifier is destroyed.

Except that's not actually how it's implemented.  A local is created in
both cases, but in one case it's a local of type "reference to parameter" 
and in the other case it's a local of type "floating point value."

-- 
plane{-z,-3normal{crackle scale.2#local a=5;#while(a)warp{repeat x flip x}rotate
z*60#local a=a-1;#end translate-9*x}pigment{rgb 1}}light_source{-9red 1rotate 60
*z}light_source{-9rgb y rotate-z*60}light_source{9-z*18rgb z}text{ttf"arial.ttf"
"RP".01,0translate-<.6,.4,.02>pigment{bozo}}light_source{-z*3rgb-.2}//Ron Parker


Post a reply to this message

From: Warp
Subject: Re: #macro question
Date: 11 Oct 2001 11:49:31
Message: <3bc5bf8b@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
:>  As a programmer I would interpret that in the way that a temporary

: Except that's not actually how it's implemented.  A local is created in
: both cases, but in one case it's a local of type "reference to parameter" 
: and in the other case it's a local of type "floating point value."

  That's why I said "I would interpret"... ;)

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


Post a reply to this message

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