POV-Ray : Newsgroups : povray.beta-test : recursion with no recursion : Re: recursion with no recursion Server Time
2 Nov 2024 03:15:59 EDT (-0400)
  Re: recursion with no recursion  
From: Thorsten Froehlich
Date: 22 Jan 2002 10:03:53
Message: <3c4d7f59@news.povray.org>

Skiba <abx### [at] babilonorg>  wrote:

> Following code returns parse error about recursion but there is no recursion
>
> //<SDL>
>   #macro F()
>     #local E=function(c){c};
>     function(k,l){select(E(k+l),0,1)}
>   #end
>   #declare E=F();
> //</SDL>
>
> Output:
>
> function(k,l){select(E(k+l),0,1)} <----ERROR
> Parse Error: Recursive function calls are not allowed!

Well, while it is not obvious, there is a recursion here:

The function E exists "twice", once as a local function and once as a global
function.  However, you insert the local function E into the global function
E via a macro.  As the parser resolves the function E after the declare, it
notices that you call a function with the same name.  As the macro merely
substituted the the F() with function(k,l){select(E(k+l),0,1)} it can no
longer know that the name E isn't meant to be the global E but the local E.
On the other hand, if you use a different name, it no longer has a problem
with it because there is no ambiguity.

Technically there is no ambiguity when using a local and global function E,
but the parser protects you from creating a recursion in either case.  I
don't think the recursive function rule for functions with the same name can
be removed because it would create ambiguities should recursive functions be
allowed in later versions.  Then the parser would no longer know for sure
whether E is of local or global scope when it finds it inside a function...


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

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