69 lines
4.1 KiB
HTML
69 lines
4.1 KiB
HTML
![]() |
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>B.4. Discussion</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Discussion">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html6272 HREF="node367.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html6270 HREF="node362.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html6266 HREF="node365.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html6274 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html6275 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html6273 HREF="node367.html"> Backquote</A>
|
||
|
<B>Up:</B> <A NAME=tex2html6271 HREF="node362.html"> Generators and Gatherers</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html6267 HREF="node365.html"> Gatherers</A>
|
||
|
<HR> <P>
|
||
|
<H1><A NAME=SECTION003540000000000000000>B.4. Discussion</A></H1>
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
The idea of generators and gatherers was first proposed by Pavel
|
||
|
Curtis. A key aspect of his proposal was the realization that
|
||
|
generators and gatherers can be implemented simply and elegantly as
|
||
|
closures and that these closures can be compiled very
|
||
|
efficiently if certain conditions are met.
|
||
|
<P>
|
||
|
First, the compiler must support an optimization Curtis calls
|
||
|
``<tt>let</tt> eversion'' in addition to the optimization methods presented
|
||
|
in [<A HREF="node368.html#RABBIT">45</A>]. If a closure is created and used entirely within a
|
||
|
limited lexical scope, the scopes of any bound variables nested in the
|
||
|
closure can be enlarged (everted) to enclose all the uses of the
|
||
|
closure. This allows the variables to be allocated on the stack
|
||
|
rather than the heap.
|
||
|
<P>
|
||
|
Second, for a generator/gatherer closure to be compiled efficiently,
|
||
|
it must be possible to determine at compile time exactly what closure
|
||
|
is involved and exactly what the scope of use of the closure is.
|
||
|
There are several aspects to this. The expression creating the
|
||
|
generator/gatherer cannot refer to a free series variable. The
|
||
|
generator/gatherer must be stored in a local variable. This
|
||
|
variable must be used only in calls of <tt>next-in</tt>,
|
||
|
<tt>next-out</tt>, and <tt>result-of</tt>, and not inside a closure. In
|
||
|
particular the generator/gatherer cannot be stored in a data
|
||
|
structure, stored in a special variable, or returned as a result
|
||
|
value.
|
||
|
<P>
|
||
|
All of the examples above satisfy these restrictions. For instance,
|
||
|
once the uses of <tt>gathering</tt> and <tt>iterate</tt> have been
|
||
|
optimized, the body of <tt>examp</tt> is as efficient as any loop
|
||
|
performing the same computation.
|
||
|
<P>
|
||
|
The implementation discussed in [<A HREF="node368.html#WATERSSERIESDESIGN">52</A>] includes a
|
||
|
portable Common Lisp implementation of generators and gatherers. Although
|
||
|
the implementation does not support optimizations of the kind discussed
|
||
|
in [<A HREF="node368.html#RABBIT">45</A>], it fully optimizes uses of <tt>gathering</tt>.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html6272 HREF="node367.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html6270 HREF="node362.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html6266 HREF="node365.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html6274 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html6275 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html6273 HREF="node367.html"> Backquote</A>
|
||
|
<B>Up:</B> <A NAME=tex2html6271 HREF="node362.html"> Generators and Gatherers</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html6267 HREF="node365.html"> Gatherers</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|