Re: Recursive environments (closures-related)

"Russ Cox" <>
17 Jan 2007 17:51:39 -0500

          From comp.compilers

Related articles
Recursive environments (closures-related) (Pupeno) (2007-01-17)
Re: Recursive environments (closures-related) (Russ Cox) (2007-01-17)
Re: Recursive environments (closures-related) (Max Hailperin) (2007-01-18)
Re: Recursive environments (closures-related) (George Neuner) (2007-01-18)
Re: Recursive environments (closures-related) (George Neuner) (2007-01-18)
Re: Recursive environments (closures-related) (Max Hailperin) (2007-01-20)
| List of all articles for this month |

From: "Russ Cox" <>
Newsgroups: comp.compilers
Date: 17 Jan 2007 17:51:39 -0500
Organization: Compilers Central
References: 07-01-050
Keywords: Lisp
Posted-Date: 17 Jan 2007 17:51:39 EST

> I've done it differently and I'd like to know if my solution is
> wrong. I first interpret the value of the binding and bind it to its
> name creating a new environment. If the new value is a procedure then
> I change its environment for the new one (the one that contains a
> reference to itself) effectively creating the recursive
> environment.

Whether this is correct depends on whether there can
be objects inside the closure with their own copies
of the environment that was used during the "interpret the value" step.
I would imagine that there can be, and therefore that
this is not correct.

For example, if we tweak your example so you are compiling

(let* ((r (lambda (x)
                        (let ((x' x))
                            (if (zero? x')
                                    (r (- x' 1))))))
    (r 10))

then I would imagine that the inner let creates an environment
containing the x' binding, and that when you patch up the
environment for the lambda closure, you do not also patch up
the environment for the inner let.


Post a followup to this message

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