POV-Ray : Newsgroups : povray.general : Strange behavior Server Time
27 Dec 2024 14:02:54 EST (-0500)
  Strange behavior (Message 1 to 5 of 5)  
From: Anthony D  Baye
Subject: Strange behavior
Date: 15 Jan 2015 22:10:00
Message: <web.54b87fbda54f2dcbd92286f0@news.povray.org>
Say I have a macro that returns values:

#macro someMacroReturningAValue(params)
    #local _RESULT = foo;
    // do stuff here...
    _RESULT
#end

I can use this macro in a computation, thusly:

object { bar translate someMacroReturningAValue(params)*x }

but I cannot set the macro as the rValue of a declaration, like so:

#declare blah = someMacroReturningAValue(params);

because povray doesn't see the semicolon at the end of the declaration.  I can
add the semicolon inside the macro, and the declaration works, but the first
usage breaks.

in order to make the declaration work without breaking the first usage, I have
to encapsulate the macro call in parentheses:

#declare blah = (someMacroReturningAValue(params));

Which, obviously, forces the macro to be evaluated first, but I have no idea why
it makes a difference, and it makes for a very confusing error.

Any explanations?

Regards,
A.D.B.


Post a reply to this message

From: scott
Subject: Re: Strange behavior
Date: 16 Jan 2015 03:01:42
Message: <54b8c566$1@news.povray.org>
On 16/01/2015 03:04, Anthony D. Baye wrote:
> Say I have a macro that returns values:
>
> #macro someMacroReturningAValue(params)
>      #local _RESULT = foo;
>      // do stuff here...
>      _RESULT
> #end
>
> I can use this macro in a computation, thusly:
>
> object { bar translate someMacroReturningAValue(params)*x }
>
> but I cannot set the macro as the rValue of a declaration, like so:
>
> #declare blah = someMacroReturningAValue(params);

The below code runs fine here, does it work ok on your installation? 
What are you doing differently (eg what is "params" defined as?). Can 
you produce just a few lines that others can run to reproduce the problem?

#macro someMacroReturningAValue(params)
     #local _RESULT = params * 2;
     _RESULT
#end
#local p = 1;
#declare blah = someMacroReturningAValue(p);


Post a reply to this message

From: eticre
Subject: Re: Strange behavior
Date: 16 Jan 2015 20:10:00
Message: <web.54b9b549ec0f5b601591f79b0@news.povray.org>
scott <sco### [at] scottcom> wrote:
> On 16/01/2015 03:04, Anthony D. Baye wrote:
> > Say I have a macro that returns values:
> >
> > #macro someMacroReturningAValue(params)
> >      #local _RESULT = foo;
> >      // do stuff here...
> >      _RESULT
> > #end
> >
> > I can use this macro in a computation, thusly:
> >
> > object { bar translate someMacroReturningAValue(params)*x }
> >
> > but I cannot set the macro as the rValue of a declaration, like so:
> >
> > #declare blah = someMacroReturningAValue(params);
>
> The below code runs fine here, does it work ok on your installation?
> What are you doing differently (eg what is "params" defined as?). Can
> you produce just a few lines that others can run to reproduce the problem?
>
> #macro someMacroReturningAValue(params)
>      #local _RESULT = params * 2;
>      _RESULT
> #end
> #local p = 1;
> #declare blah = someMacroReturningAValue(p);

hallo

this fail

#declare rndx=seed(123);
#macro rnr(nrx,mii,mxx)
 #if(mii>=0)
   (rand(nrx)*(mxx-mii+1)) + mii
 #else
   mii+(mxx-mii)*rand(nrx) /////////  LINE 40
 #end
#end

#local d=0;
#local d=rnr(rndx,-20,20);

 line 40: Parse Error: All
 #declares of float, vector, and color require semi-colon ';' at end if the
 language version is set to 3.5 or higher. Either add the semi-colon or set the
 language version to 3.1 or lower.
Fatal error in parser: Cannot parse input.
Render failed

this work ok

#declare rndx=seed(123);
#macro rnr(nrx,mii,mxx)
 #if(mii>=0)
   (rand(nrx)*(mxx-mii+1)) + mii
 #else
   mii+(mxx-mii)*rand(nrx)
 #end
#end

#local d=<0,0,0>;
#local d=<rnr(rndx,-20,20),0,0>;


Post a reply to this message

From: clipka
Subject: Re: Strange behavior
Date: 16 Jan 2015 22:50:01
Message: <54b9dbe9$1@news.povray.org>
Am 17.01.2015 um 02:05 schrieb eticre:

> this fail
>
> #declare rndx=seed(123);
> #macro rnr(nrx,mii,mxx)
>   #if(mii>=0)
>     (rand(nrx)*(mxx-mii+1)) + mii
>   #else
>     mii+(mxx-mii)*rand(nrx) /////////  LINE 40
>   #end
> #end
>
> #local d=0;
> #local d=rnr(rndx,-20,20);

This is a known issue rooted deep in the current parser (and not due to 
be fixed before implementation of a brand new parser); to work around, 
first assign the expression to a local variable, then finally "return" that:

   #macro rnr(nrx,mii,mxx)
     #if(mii>=0)
       #local result = (rand(nrx)*(mxx-mii+1)) + mii;
     #else
       #local result = mii+(mxx-mii)*rand(nrx);
     #end
     result
   #end

The issue reported by the OP, however, is that this construct allegedly 
doesn't always seem to work either; but for the time being I presume 
that Anthony accidently did something wrong.


Post a reply to this message

From: Anthony D  Baye
Subject: Re: Strange behavior
Date: 16 Jan 2015 23:20:01
Message: <web.54b9e246ec0f5b60bd92286f0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 17.01.2015 um 02:05 schrieb eticre:
>
> > this fail
> >
> > #declare rndx=seed(123);
> > #macro rnr(nrx,mii,mxx)
> >   #if(mii>=0)
> >     (rand(nrx)*(mxx-mii+1)) + mii
> >   #else
> >     mii+(mxx-mii)*rand(nrx) /////////  LINE 40
> >   #end
> > #end
> >
> > #local d=0;
> > #local d=rnr(rndx,-20,20);
>
> This is a known issue rooted deep in the current parser (and not due to
> be fixed before implementation of a brand new parser); to work around,
> first assign the expression to a local variable, then finally "return" that:
>
>    #macro rnr(nrx,mii,mxx)
>      #if(mii>=0)
>        #local result = (rand(nrx)*(mxx-mii+1)) + mii;
>      #else
>        #local result = mii+(mxx-mii)*rand(nrx);
>      #end
>      result
>    #end
>
> The issue reported by the OP, however, is that this construct allegedly
> doesn't always seem to work either; but for the time being I presume
> that Anthony accidently did something wrong.

I could have been certain that I did exactly this, but I suppose that
considering the complexity of what I was working on, there was something I
missed.

my simple test, also works for both cases:

#version 3.7;

light_source { <5, 10, -30> rgb 1 }
camera {
  perspective
  location <0.0, 0.0, -10.0>
  up y
  right x*(image_width/image_height)
  look_at 0
  }

#macro mrav(V)
  #local result = V;
  // stuff and junk...
  result
#end

#declare myval = mrav(5);

sphere { 0.0 0.125 pigment { rgb 1 } translate mrav(5)*x }

Regards,
A.D.B.


Post a reply to this message

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