POV-Ray : Newsgroups : povray.general : Macros and Arrays : Macros and Arrays Server Time
29 Jul 2024 20:15:52 EDT (-0400)
  Macros and Arrays  
From: lkreinitz
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

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