POV-Ray : Newsgroups : povray.general : Macros and Arrays Server Time
26 Nov 2024 11:37:08 EST (-0500)
  Macros and Arrays (Message 1 to 2 of 2)  
From: lkreinitz
Subject: Macros and Arrays
Date: 16 Sep 2010 13:40:01
Message: <web.4c9256447ceb437d8993ef290@news.povray.org>
Would anyone know why this doesn't work

#macro AtIndex( A , I )
  #if ( dimension_size(I,1) = dimensions(A) )
    A[
    #local ii = 0;
    #while ( ii < dimensions(A) )
      #if (ii > 0 )
        ][
      #end
      I[ii]
      #local ii = ii + 1;
    #end
// uncomment ';' to avoid error
    ]  // ;
  #else
    #error "Dimension Mismatch"
  #end
#end

#declare zippy = array[2][2]
#declare index = array[2] { 0, 1}
#declare zippy[0][1] = 2;
#declare tryit = AtIndex(zippy,index)
#debug Str(tryit)
#debug "\n"


What I'm aiming for is the following

#declare AtIndex(A, I) = 1;
    AND
#declare tryit = AtIndex(A,I) ;

I can get the second by uncommenting the semicolon
But I would like the ability to assign to the array as well.

I can make it work with a second macro taking the assignment value

#macro SetAtIndex( A , I , N)
  #if ( dimension_size(I,1) = dimensions(A) )
    #declare A[
    #local ii = 0;
    #while ( ii < dimensions(A) )
      #if (ii > 0 )
        ][
      #end
      I[ii]
      #local ii = ii + 1;
    #end
    ]  = N ;
  #else
    #error "Dimension Mismatch"
  #end
#end

I just think it would be neater with 1 macro

I think this is related to
When parsing an array it does not like macros as values

#declare  uuu = array[3] {
 Shear_Trans(x,z,y),                // this line produces an error
 Shear_Trans(y,-x,z) }

I thought that all the macro was doing was substituting new symbols
There are work arounds ( Assigning after declaring etc. )
but It's kind of annoying.


Post a reply to this message

From: John VanSickle
Subject: Re: Macros and Arrays
Date: 18 Sep 2010 05:29:03
Message: <4c94865f$1@news.povray.org>
On 9/16/2010 1:39 PM, lkreinitz wrote:
> Would anyone know why this doesn't work
>
> #macro AtIndex( A , I )
>    #if ( dimension_size(I,1) = dimensions(A) )
>      A[
>      #local ii = 0;
>      #while ( ii<  dimensions(A) )
>        #if (ii>  0 )
>          ][
>        #end
>        I[ii]
>        #local ii = ii + 1;
>      #end
> // uncomment ';' to avoid error
>      ]  // ;
>    #else
>      #error "Dimension Mismatch"
>    #end
> #end

You appear to be trying to access a member of an array with any number
of dimensions using the members of another array as the indices.  Why
do you need a general-purpose solution for this?  Your array access 
should be tailored to the specific array you are using, and accessing 
should not be left up to a macro.

> I thought that all the macro was doing was substituting new symbols
> There are work arounds ( Assigning after declaring etc. )
> but It's kind of annoying.

Yes, the macros are primarily symbol-substitution, but there comes a 
point at which parsing starts without further substitution.  If your 
intended expression is not fully built at that point, there will be 
problems.

Remember that the purpose of the scene description language is to 
describe the scene you want to render.  It is not intended to be a 
general-purpose programming language.

Regards,
John


Post a reply to this message

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