POV-Ray : Newsgroups : povray.newusers : Use of macros returning values Server Time
1 Nov 2024 11:13:37 EDT (-0400)
  Use of macros returning values (Message 1 to 7 of 7)  
From: Steve
Subject: Use of macros returning values
Date: 7 Sep 2005 11:25:00
Message: <web.431f0609ffcf6ed9b279c3b00@news.povray.org>
I'm attempting to write a macro that looks up a value in a table, as follows

#macro __get_table_element1( tbl, e, n )

 // Macro to calculate interpolated value from table.

 #local tick = clock * 1399;
 #local ftick = floor( tick );
 #local i0 = ( ftick * n ) + e;
 #local i1 = i0 + n;

 #if ( 1399 - ftick )

  ( tbl[i1] )

 #else

  ( tbl[i0] )

 #end

#end

When I invoke the macro, as here

 #local q10 = __get_table_element1( clip_array, 0, 6 )

for example, I get the folloiwng error:

File: fnord  Line: 141
Possible Parse Error: All #version and #declares of float, vector, and color
 require semi-colon ';' at end.

In order to get the script to work, I have to run in version 3.1 mode.

If I add a semicolon, either after the return value or at the end of the
local declaration, I get a syntax error.

I believe I've R'd TFM, but I may have missed something.

Thanx.


Post a reply to this message

From: Mike Williams
Subject: Re: Use of macros returning values
Date: 7 Sep 2005 12:00:21
Message: <437diPAM6wHDFwLB@econym.demon.co.uk>
Wasn't it Steve who wrote:
>I'm attempting to write a macro that looks up a value in a table

Why not just add the ";"s that it's asking for. This works:

#macro __get_table_element1( tbl, e, n )

 // Macro to calculate interpolated value from table.

 #local tick = clock * 1399;
 #local ftick = floor( tick );
 #local i0 = ( ftick * n ) + e;
 #local i1 = i0 + n;

 #if ( 1399 - ftick )

  ( tbl[i1] );

 #else

  ( tbl[i0] );

 #end

#end


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Warp
Subject: Re: Use of macros returning values
Date: 7 Sep 2005 13:08:02
Message: <431f1e72@news.povray.org>
Mike Williams <nos### [at] econymdemoncouk> wrote:
> Why not just add the ";"s that it's asking for.

  Because you might want to use the macro somewhere where you shouldn't
use a ";".

  The proper way is:

#macro Whatever(...)
  #if(something)
    #local Result = foo;
  #else
    #local Result = bar;
  #end

  Result
#end

-- 
                                                          - Warp


Post a reply to this message

From: Florian Brucker
Subject: Re: Use of macros returning values
Date: 7 Sep 2005 13:09:56
Message: <431f1ee4$1@news.povray.org>
> Why not just add the ";"s that it's asking for. This works:
> 
> #macro __get_table_element1( tbl, e, n )
> 
>  // Macro to calculate interpolated value from table.
> 
>  #local tick = clock * 1399;
>  #local ftick = floor( tick );
>  #local i0 = ( ftick * n ) + e;
>  #local i1 = i0 + n;
> 
>  #if ( 1399 - ftick )
> 
>   ( tbl[i1] );
> 
>  #else
> 
>   ( tbl[i0] );
> 
>  #end
> 
> #end

Adding the ";" to the end of the declaration, as in

  #local q10 = __get_table_element1( clip_array, 0, 6 );

would be even better, because it does not break things like

  #local q10 = __get_table_element1( clip_array, 0, 6 )*100;


HTH,
Florian


Post a reply to this message

From: Mike Williams
Subject: Re: Use of macros returning values
Date: 7 Sep 2005 13:40:41
Message: <R1u3yCAYQyHDFwu0@econym.demon.co.uk>
Wasn't it Florian Brucker who wrote:
>
>Adding the ";" to the end of the declaration, as in
>
>  #local q10 = __get_table_element1( clip_array, 0, 6 );
>
>would be even better

An excellent solution apart from the fact that it still throws the
error.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Steve
Subject: Re: Use of macros returning values
Date: 7 Sep 2005 13:45:01
Message: <web.431f2695eb77a74eb279c3b00@news.povray.org>
Florian Brucker <tor### [at] torfboldcom> wrote:
> > Why not just add the ";"s that it's asking for. This works:

Thanx.  For some reason it didn't work the first time I tried it.  I
probably had something else hosed that was masking the real solution.


Post a reply to this message

From: Florian Brucker
Subject: Re: Use of macros returning values
Date: 7 Sep 2005 18:49:50
Message: <431f6e8e$1@news.povray.org>
> An excellent solution apart from the fact that it still throws the
> error.

Ah, shame on me, I didn't test it :(

It felt right, but now I see that it needs Warp's addition to work. 
Sorry for the confusion!


Florian


Post a reply to this message

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