<div>Hi Matthew,</div>
<div>&nbsp;</div>
<div>Thank you for the answer. I suspected as much as far as indexing the stack. My question is related to the creation of closures. When the values are obtained from the stack is only the &quot;top&quot; of the stack accessed (
i.e. all values are local to the funtion being evaluated that will return the closure) or do free variables still exist at runtime (i.e. the indexing can be to bindings that are not local to the function being evaluated)?
</div>
<div>&nbsp;</div>
<div>To illustrate this:</div>
<div>&nbsp;</div>
<div>(define (f x)</div>
<div>&nbsp;&nbsp; (define (g y)</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (.....y......x....)))</div>
<div>&nbsp;</div>
<div>Clearly, y is local and only requires indexing the top of the stack. The reference to x is what I am inquiring about. Are the values pushed onto the stack for f accessed while g is executed or is g lifted to the global level (and x added as a parameter) to make all accessess to the top of the stack at runtime?
</div>
<div>&nbsp;</div>
<div>Cheers,</div>
<div>&nbsp;</div>
<div>Marco<br><br>&nbsp;</div>
<div><span class="gmail_quote">On 5/20/07, <b class="gmail_sendername">Matthew Flatt</b> &lt;<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Bindings are always accessed by offset into a value/box stack. When a<br>closure is applied, its content is unpacked into this stack. When a
<br>closure is created, each value/box added to the closure is obtained<br>from the stack by offset. The offsets are always determined at compile<br>time (i.e., local-variable names are all gone by run time).<br><br>Hope that helps,
<br>Matthew<br><br>At Fri, 18 May 2007 20:31:14 -0400, &quot;Marco Morazan&quot; wrote:<br>&gt; Thank you for your response Matthew. Flat closures need to be &quot;populated&quot;<br>&gt; with the bindings of the free variables. Are local functions lambda-lifted
<br>&gt; (or joisted) to simplify this process or is the environment traversed at<br>&gt; runtime to determine the bindings?<br>&gt;<br>&gt; Thanks,<br>&gt;<br>&gt; Marco<br>&gt;<br>&gt;<br>&gt; On 5/18/07, Matthew Flatt &lt;
<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>&gt; wrote:<br>&gt; &gt;<br>&gt; &gt; At Fri, 18 May 2007 13:59:22 -0400, &quot;Marco Morazan&quot; wrote:<br>&gt; &gt; &gt; Can anyone point me to a document or web page that describes how
<br>&gt; &gt; closures<br>&gt; &gt; &gt; are represented in PLT Scheme?<br>&gt; &gt;<br>&gt; &gt; What level of detail are you looking for?<br>&gt; &gt;<br>&gt; &gt; For the basic architecture, there&#39;s no document specific to PLT Scheme,
<br>&gt; &gt; but the implementation is one of the typical points in the spectrum<br>&gt; &gt; described by textbooks. MzScheme&#39;s closures are essentially &quot;flat&quot;: a<br>&gt; &gt; code pointer is packaged with the values (or boxes, in the case of
<br>&gt; &gt; mutable variables) associated with its free variables. For module-level<br>&gt; &gt; bindings, though, there&#39;s an extra indirection: one reference in the<br>&gt; &gt; closure record to an array of module bindings (and the array is shared
<br>&gt; &gt; for all closures in the same module).<br>&gt; &gt;<br>&gt; &gt; If you want to know the actual byte layout for some reason, see<br>&gt; &gt; `Scheme_Closure&#39; and `Scheme_Native_Closure&#39; in<br>&gt; &gt; &quot;src/mzscheme/src/schpriv.h&quot;. Beware that the `vals&#39; array is not
<br>&gt; &gt; actually an array of values; it can contain mutable-variable<br>&gt; &gt; indirections and a module-level array, as noted above.<br>&gt; &gt;<br>&gt; &gt; Matthew<br>&gt; &gt;<br>&gt; &gt;<br></blockquote></div>
<br>