Re: recursive nested functions

Chris F Clark <>
Sun, 27 Jun 2010 18:19:11 -0400

          From comp.compilers

Related articles
recursive nested functions (nojb) (2010-06-25)
Re: recursive nested functions (Chris F Clark) (2010-06-27)
Re: recursive nested functions (Gene) (2010-06-27)
Re: recursive nested functions (BGB / cr88192) (2010-06-28)
| List of all articles for this month |

From: Chris F Clark <>
Newsgroups: comp.compilers
Date: Sun, 27 Jun 2010 18:19:11 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 10-06-078
Keywords: optimize
Posted-Date: 28 Jun 2010 00:17:41 EDT

nojb <> writes:
> I'm writing a compiler for a language that admits recursive nested
> functions and I am stuck trying to figure out how to handle them. My
> objective is to lift all nested functions to top level and pass all
> their free variables explicitly as parameters. For this, I have to
> figure out which variables are free. So when I'm analyzing the body
> of each function, I record its free variables. But then obviously when
> I come across a function call, I have to add _its_ free variables to
> the list of the enclosing function. You can see how this will loop
> endlesly if we allow recursive functions...

It won't loop endlessly, there is a fixed upper bound, a function f()
with a finite set of free variables: v1, v2, ... will not introduce
any new free variables when it calls itself recursively (even
indirectly). Thus, when you take the closure, it is a closed finite
set that is bounded by the union of free variables of the consituent

Hope this helps,

Chris Clark email:
Compiler Resources, Inc. Web Site:
23 Bailey Rd voice: (508) 435-5016
Berlin, MA 01503 USA twitter: @intel_chris

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.