POV-Ray : Newsgroups : povray.animations : Recursive functions with macros : Re: Recursive functions with macros Server Time
28 Apr 2024 15:00:02 EDT (-0400)
  Re: Recursive functions with macros  
From: Chris B
Date: 7 Oct 2008 19:02:14
Message: <48ebea76@news.povray.org>
"peter" <den### [at] webde> wrote in message 
news:web.48ebd8c3cab65715180445b0@news.povray.org...
> Hello there,
>
> I am trying to create a "sirpinski-sponge" by using a macro in a 
> recursion. The
> macro "sirpinski" calls itself with different parameters. But I end up 
> getting
> screwed up pictures or an error message:
>
> Parse Error: Too many nested symbol tables
>
>  0:00:00 Reclaiming memory
> Memory leakage detected, see file 'Memory.Log' for list
>
> What is a symbol table? What does this message mean? Is it possible to use
> macros the way I try to?

A symbol table is used to store identifiers. Each time a macro is called it 
would need a new symbol table for the local variables (including parameter 
values). I would think that these errors would result from failure to 
establish a suitable exit criteria resulting in the macro repeatedly calling 
itself until the limit is reached (the limit seems to be about 98).

One way to avoid this situation is to declare a global variable that keeps 
count of the recursion depth and use it to prevent the macro from calling 
itself once a defined limit has been reached. The macro can increment this 
variable at the start and decrement it at the end.

#declare Depth = 0;

#macro Test ()
  #declare Depth = Depth + 1;
  #debug concat(str(Depth,3,0),"\n")
  #if(Depth<98) Test() #end
  #declare Depth = Depth - 1;
#end

Test()

The other way that I see Warp has already mentioned is to recode it using 
#while loops thus avoiding self calling macros.

Regards,
Chris B.


Post a reply to this message

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