POV-Ray : Newsgroups : povray.animations : Recursive functions with macros Server Time
29 Mar 2024 11:26:40 EDT (-0400)
  Recursive functions with macros (Message 1 to 4 of 4)  
From: peter
Subject: Recursive functions with macros
Date: 7 Oct 2008 17:50:01
Message: <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?

Peter


Post a reply to this message

From: Warp
Subject: Re: Recursive functions with macros
Date: 7 Oct 2008 18:28:07
Message: <48ebe277@news.povray.org>
peter <den### [at] webde> wrote:
> 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

  There's a limit how many times a macro can be called recursively. This
limit is relatively small.

  Unfortunately the only solution to this is to try to create the object
iteratively (ie. with #while loops).

-- 
                                                          - Warp


Post a reply to this message

From: Chris B
Subject: Re: Recursive functions with macros
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

From: peter
Subject: Re: Recursive functions with macros
Date: 23 Oct 2008 16:30:01
Message: <web.4900dd9e62d4db5f39c434f20@news.povray.org>
Thank you Chris and Warp for your help. I solved the problem by using local
variables. But the scene took way to long to render so I recoded it using an
iteration with #while loops. It worked just fine.

It took me a while to answer, I thought I'd be notified when there is a reply to
my post, but I wasn't. I'll check if I can change that.

Peter


Post a reply to this message

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