Escolar Documentos
Profissional Documentos
Cultura Documentos
Transformation
of Series Expressions
into Loops
RICHARD C, WATERS MIT Artificial Intelligence Laboratory
The that
benefits are
of programming easier
this reasons:
in
style than
used less
known.
In
particular, expressed
as of it could expression of
are expressed
as compositions to
kind (1)
operating
anywhere familiar poor
on sequences/vectors/streams algorithms
as often kind this this for near with support
elements
~Tnfortunately, least loops, (3) when In troducing any three (2)
understand
of most expression
modify
not are provide efficient second
most support
programming is provided,
kmd
expression;
language. called
and
third
problems
can
be
largely
solved
by
in-
series, extension)
set of procedures converts expressions of high in Pascal. Techniques] Language E.1 most series
operating series
and into
a preprocessor efficient grammers rfemonst Categories tional) Lzsp; D.3.3 loops. stay rates
If pro-
imposed,
A Common
A prototype
and
Subject
(Func34
Programming; [Programming
[Programming
ionsPascal,
Constructs-control nptr,mr,zatzo~
gramming
Languages]:
Processorspreprocessors,
Automatic
[Data
Structures]
[Pro.
Programmingprogram
tran.sfownatton
Sequences,
Vectors,
Streams,
Series
1. SEQUENCE EXPRESSIONS
The mathematical
term sequence refers to a mapping from the non-negative integers subset of them) to values. Whether called sequences [5, 37], vec-
tors [24, 32, 33, 37], lists [37], streams [6, 20, 26, 31], sets [36], generators [19, 49], or flows [35], data structures providing complete (or partial) support for mathematical sequences are ubiquitous in programming. is as mutable aggregate storoperations for accessing and The most common use for sequence data structures age. Almost every programming language provides altering the elements of at least one such structure.
Authors 02139. Permission to copy without fee all or part commercial of this material is granted provided that the copies are not address: MIT Artlficial Intelligence Laboratory,
545 Technology
Square,
Cambridge
MA
copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to repubhsh, requires a fee and/or specific permission. C 1991 ACM 0164-0925/91/0100-0052 $01.50
made or distributed for direct advantage,
ACM Transactions on Programming Languages and Systems, Vol. 13, No. 1, January 1991, Pages 52-98
the ACM
53
is potentially
Most algorithms
also be expressed as functional expressions manipulating sequences. For example, consider the problem of computing the sum of the squares of the odd numbers in a file Data. program.
type
This
a loop
Integer;
Pascal
[25]
FileOf
function FileSumLoop (var Data: FileOf Integer) var Sum: Integer; begin Reset (Data) ; sum := o; while not Eof (Data) do begin if Odd(Data-) then Sum := Sum+ Sqr~Data-); Get (Data) end; FileSumLoop := Sum end
: Integer;
numbers This
below.
that four subroutines have been previously defined: collect sum computes the sum of the elements of a sequence; MapFn computes a sequence from a sequence by applying the indicated function to each element a predicate;
FileOf (Sqr, Integer):
Choose If
selects the
satisfy
Data:
creates a sequence of
:= CollectSum(MapFn
ChooseIf(Odd,
ScanFile(Data))))
who the
are
not
to may
functional make
programming, preferable.
the
greater
fathe
it appear First,
FileSum
thepatterns apart.
are mixed
each of
isdistilled to o and
a subroutine.
repetitively apart,
subcomputations of the expression This FileSum makes makes easier FileSum oft he subcomput
can be understood of the actions than File can be altered of the the Since the reusability correct they
SumLoop.
separation subroutines
to modify.
enhances
y in two
is less chance
In addition, very
Unfortunately, like
there
problems most
inhibit
most
programmers provide
13, No,
Fi leSum.
ACM TransactIons
First,
programming
Languages and
languages
Systems, Vol.
on Programming
1, ,January
54
Richard C. Waters procedures on their that operate onsequences as aggregates, rather than merely
predefined operating
individual
elements.
Common Lisp, where a wide range of sequence operations are available, sequence expressions are typically so inefficient (2 to 10 times slower than equivalent loops), that programmers are forced to use loops whenever efficiency matters. The primary source of inefficiency when evaluating sequence expressions is the physical creation of intermediate sequence structures. This requires a significant amount of space overhead (for storing elements) and time elements and paging). The key to solving the efficiency tion that it is often possible the crest ion of intermediate straightforward to transform A transformational overhead (for accessing problem is the realizainto a form where For example, it is
to transform sequence expressions sequence structures is eliminated. the expression to the efficient evaluation
approach
has been used in a number of contexts. For example, it is used by optimizing compilers [12, 22], Wadlers Listless Transformer [39, 40] which can improving
efficiency of programs written in a Lisp-like language, and Bellegardes transformation system [7, 8] which can improve the efficiency of programs written in the functional shown that
data base
programming
queries. it is not
language
Goldberg
the transformational
possible There from
sequence this
an efficient the
loop. issue
with
programmer programmer
simply the
transform defining
be transformed. transformed individual The vantage wit bout difficult they remain quite issue The tions tion identify every restrict Second, tions. Sections prehensive language. expression have completely quite simple into
Second,
one can
develop the
what
can be
with
transformability
by
all
the
above,
has
the
ad-
having
no way
of knowing
whether
sequence
expression In
expressions
be transformed. a favor
an algorithm
an untransformable to hide
a transformable y from
As a result,
it is not
of t ransformabilit most that important can a class system ions, the serve
programmers. of the the loops. research reported here is a set of restricto the 2, these always embodies other be used into type any called
1991.
of sequence The
expressions of optimizable
be completely some
transformed.
that the
except than
In particular,
Wadlers approach
communicative a new
efficient is done
expressions data
programming
sequence
Vol.
series and
Systems,
13, No.
1, January
Automatic Transformation
preprocessor support key that the for restrictions restriction that series can transform the by
55
The of the so
utilizes cannot
is enforced
set of predefined
each series
expresis use
optimizable, This
can have
efficient. each
by the
series
expressions
series
once
be optimized. data type support in Section can can with be used. and a broad for series suite with of associated Lisp. Lisp functions. This imexample [29, 46] series ex4
series
is in Common an extended
4, along
that
series can
expressions
also
be added
implementation of Section
is presented pressions
an extended
on whichever
series
expressions
capable
are not
necessary
expressions. as expressions
while series
algorithms of series,
can be expressed
series
of sequences
and other
approaches
to understand
1.1 Getting
To fully able
Rid of Loops
the practical one must for loops. of series. essentially that case impact return The The of series to the program series expressions perspective File to the and in general of sequence and optimizexpressions based on the and is
appreciate
ones
implementation
expression
in it is optimizable
identical
As a result, same the result deof else, loops by them. the (At this many is is
FileSum
using tailed
abstract without
denote
same
computation.
Using
expression price
in anything
other
the
related can
percentage
as an optimizable series operations a single the to familiar is at least the familiar that series can loop
at ions used in it into entire loop many becomes fragments as there on how fragments
correspond
as long study
ACM
in separating
[42] revealed
Transactions
loops
on Programmmg
13, No
1, January
56
mers looping with some
Richard C. Waters
write are constructed (A somewhat solely similar by combining study just a few in dozen familiar
typically
[16].)
indicates the
95% of loops
of opt imizable
familiar
practical
expressions
can
be summarized
as follows:
Optimizable as structured
Structured capable there control constructs anything a few every They
In addition, Nevbetter to be in a way do not they where one can can be of the is quite things step
structured not the and have that in because same modify. exactly cannot a much constructs there
control they
more
be expressed They
is much algorithms
to understand expressions
Optimizable
to be expressed to be expressed
control needed,
down some
expressed
expressions. and
most in
these
programs
used whenever
loops.
in conciseness,
2. OPTIMIZABLE
As noted above, is the First, used
SEQUENCE
the creation primary
EXPRESSIONS
source may of inefficiency intermediate waste time Second, of time when sequences. computing even and a physical elements elements associated does not when data space. can are not with save be overcome computed sequences. constructing any when space. sequence by using until they evaluating There sequence structure sequence are two elements exthat of an
of physical of the
aspects
intermediate elements The problem evaluation evaluation all used, The (Each reuse of the much
containing
sequence
are needed. intermediate wasted, elements. crest ed. a later All and
(This
also
makes
it easy
to support
unbounded
in sit uat ions where and is required a physical recomputation. physical computing somewhere
the elements
because
to decide after
to compute
intermediate )
element
has to be stored
constructing
of the
associated
unused
be eliminated
ACM TransactIons
by pipelining
on Programming
evaluation
and Systems,
of a sequence
Vol. 13, No
Languages
1, January
57
if
1 (pipelined)
of E. any First,
The two
evaluation
E is pipelined
once. Second, and then
if the following
S computed
by any
at most to
is computed, other
is used
be used
element
of S is computed. 1 is that, within while some of the of E. procedures is needed each creates in this 5). by of
implication buffer
of Definition elements
sequence
themselves,
no buffering
sequence that
Rather, that
is transmitted procedures the statement Data. each The value program using
one element
procedure of the
below
most of series
examples of the
is written
the second
Pascal body
discussed Vals of
in Section values
in the
of CosMax computes
numbers
statement The
scaled the
by its
cosine.
statement
maximum
values.
function CosMax (var Data: FileOfReal) : Real; var Vals, ScaledVals: series of Real; begin Vals : = ScanFile(Data) ; ScaledVals := MapFn(/, Vals, MapFn(Cos, Vals)) CosMax : = CollectMax(ScaledVals) end The and body of CosMax can be evaluated of which in four data are structure. not. The The numbers The data cosine in many ways,
some elined
of which method
some
standard in the
non-pip file
steps.
are read
and
stored
physical
intermediate in a t bird
structure.
cosine
physical pipelined
element
intermediate standard
structure
is determined. of evaluation a number scaled value on the the neither they input file, it an the are time
In contrast, numbers accumulator number, discarded (as opposed is as efficient (at input cosine. place must compile number (series its one
a time divided
from to Since
is immediately
is used
update
processing,
before
number then
If the basic
for what
to evaluate the
at compile
evaluation time)
or at run
program
below. by the
a sequence
is impossible, time
because evaluation
the two
of Vals the
immediatelyi.e., However,
as part division
as the
of a division.
ACM
be performed
Systems, Vol.
after
Transactions
on Programming
Languages
1, January
58
Richard C. Waters
computed elements
computation been
of the
sum As
cannot a result,
have an
computed. data
elements
of Vals
intermediate
structure,
it is time
to do the
divisions.
function NormalizedMax (var Data: FileOfReal) : Real; var Vals, ScaledVals: series of Real; begin Vals := ScanFile(Data); ScaledVals := MapFn(/, Vals, Series(CollectSum(Vals))); NormalizedMax := CollectMax(ScaledVals) end Given that the existence pipelining system, further of programs can only it invaluable given advantages like NormalizedMax, it is clear that arrysystem expressions. explicit. failto is given the meet Ifin the a clear
supports the
class of sequence to be made expressions programmer are not, and they so that sufficient However, is of greater algorithms the pipelining. can
which
programmer specifying are a number benefit. can Second, succeed check the in
to change to have
can be pipelined.
would
which the
sequence
of reasons
a somewhat
actually
programmers
here
being using
excessively the
expressions
at compile 2.1 In
by transforming
algorithms
Straight-Line
the interest
Expressions
of simplicity, optimizable not ,sub ject control flow sequence to any flow could in expressions are required cent rol must to be
flow.
be prothis
control
in Section conditional
6 in a number control
sequence
operations
Restrictiorl
line comput aspect sequence
1 (straight-line)
at ions. of the simplicity the In the of each of the other
Optimizable
sequence
expressions
must
be straight-
it For
to be represented
using
Figure and
Normal izedMax.
on the hatched of
is represented only
13, No
by arrows
indicate values.
Languages
flow
of sequences.
indicate
ACM
Because
and Systems.
expressions
1, January 1991
int crest
TransactIons
on Programming
Automatic Transformation
59
Fig.
1.
The
sequence
expression
in Normal
izedMax.
straight-line
ones,
there
is no need
to consider
control
flow.
be determined
computation
Restriction statically
each sequence
2 (static
value defined
analyzable.
analyzable calls
in the
and
in an optimizable Further,
sequence
in a sequence limited
structure. compile-time
storage
sequence for
practicality
y of this
[12], Hibol
allows sequence to the the for
[33].
procedures before its to be first This calls.
user-defined
However, that
be available
of use.
inline
compilation
of procedure
be pipelinable,
be the
case is to one a
process starting
every
at a time to pick
is the
Restriction
expression the order elements starting
must
Every procedure called by an optimizable sequence 3 (preorder) A procedure is preorder if and only if it processes be preorder. of its sequence the first element.
on Programming Languages and Systems, Vol. 13, No. 1. January 1991.
of each with
inputs
and
outputs
one at a time
in ascending
ACM Transactions
60
It than
Richard C. Waters
to note In referring rather this to than not consider that the the restriction word above applies is used while The term to procedures, to refer the of the rather
paper,
procedure
function, function.
implements
function
applies
is
to
preorder
it is a property relationship
a computaand the
is performed, example,
of the
mathematical the
between elements
the
input
sum
of the ways,
Sumand the
different
some operates
of which
CollectSum adding
elements choose
However, or in some
elements
in reverse
or two
at a time,
non-preorder sequence
be implemented not than more limit In any what addition, other further buffering
procedure. but
rest riction
be required.
is discussed
of this
Before
it is useful
Definition on-line
all the on-line the on-line ports if and other input output
2 (on-line
only on-line is read, element
a sequence
of the on-line
of each
of each on-line
second
so on for the
elements.
of a procedure is not
on-line,
procedure
as a whole
is on-line.
or procedure Definition applies term of one some these inputs line of the There has only processing.
it is off-line. standard as well 2 applies operation Mapping and some the result first definition as whole of the procedures. rather term
2 extends
on-line
Like than the >
it
of the
Definition consider sequences. are on-line way, writ reading ing the
For example,
the
a procedure
of which
MapFn operates
in an on-line
as the
However, the
one could
mapping
in an offwriting
reading between
preorder However,
procedure than
one sequence
constrained can
1991.
preorder
In particular,
function
1, January
be implemented
Automatic Transformation
as a preorder on-line For satisfy become remain input procedure, there are many
61
as
be implemented
procedures. example, consider P. problem of the step with It the operation of selecting for some writing of the gets takes returns first out two this to the elements of a sequence as an input output soon that on-line do not cannot as an
procedure.
is skipped, a related
of phase. sequences, the elements It However, the in a sequence of the is also note two this second that impossible of boolean sequence for this the output be on-line. in order can to be
some
other to true
correspond
sequence.
procedure. in one
inputs paragraph
individual
to be on-line
functions that
in ways
are partly
beginning
section why
of on-line
to understanding
CosMax can be pipelined Recall the and put. way that the the output requires
ure 2) cannot
be pipelined,
constraints CollectSum
must
quires
that Series
be available
it can start
However,
that
element
be available if
second
of the
of ScanFile than
Unfortunately,
output The
of ScanFile
contains
essence
of the problem
of interacting
constraints.
constraints
are inconsistent
in Figure
a cycle
constraints, data-flow cycle. then all of the are not example, though data it flow arcs
In particular, data
MapFn form
completely of a data
and
cannot
the presence
implies they
the constraints
necessarily
expression lead
in Figure It
contains cycles
a non-directed
is possible
Restriction
sequence and two only ports
4 (on-line
must
Every through
be on-line.
ACM
on Programmmg
Languages
and
Systems,
Vol.
13. No.
1, January
1991.
62
Richard C Waters
Fig.
2.
Theseqllence
expression
in
NormalizedMax
Fig.
3.
The
sequence
expression
in CosMax.
in
the It does
of ScanFile. because
non-directed
data-flow and
2 is off-line, of Series
both
of CollectSum
is off-line
because
input To
is off-line. why on-line 2 and If cycles guarantee pipelinability, of two the the branches processing cycle that port will while and whether processing relevant to the is each the the at it is useful (an upper to think branch along
understand cycles in
Figures
a lower two
pipelining be
synchronization pletely branch (as in Figure be balanced. is on-line, processing cycle. ) The gram This with viding output PositiveMax program ChooseIf the ith
step and
branches is not,
balance. two
cent rast,
of ScanFile
relationship ports
between
either
because off-line
pipelining.
is
is identical
replaced by di-
are computed
of Vals.
function Posit iveMax (var Data: FileOfReal) : Real; var Vals ,ScaledVals : series of Real; function Positive (X: Real) : Boolean; begin Positive := X>O. O end; begin Vals := ScanFlle(Data); ScaleclVals := IlapFn(/, Vals, ChooseIf(Positive, Vals)); Posit iveMax := CollectMax (ScaledVals) end
ACM Transactions on Programming Lan~ages and Systems, Vol. 13, No. l,,January 1991.
Automatic Transformation
63
Fig. 4.
The qualitative
cycle restriction.
As phase
the
two
branches
of the
output
as soon first
of Vals element
situation, the t bird delay pipelining delay. cycle branches and only
be available on the
of Vals iveMax
computed. small
Posit is only
be very
zero. will it
However, never be
possible is stronger to
when
it is known it has
there because
restriction
than
is possiboth be
ports
therefore
are identically
cycle
2 were
would
be possible on the
expressions forces in
be individually
optimizable 4. the In At
qualitative
Figure
restriction
forces
structure however,
bottom arbitrarily
participating outputs
overall
inputs data
connecting
clusters
cannot
the
limits
imposed
cycle
several
of the most
commonly
used sequence
sequences
in a completely stringent
Nevertheless, on optimizable
of the restrictions
Transactions
on Programming
Languages
and
Systems,
Vol.
13, No.
1, <January
1991.
64 25
The
Summary
four
restrictions
is optimizable
It is a straight-line It is statically procedure non-directed restriction than analogous at compile pairs that 4. every
computation; and
by it is preorder; cycle
and
in it is on-line. the algorithms that time. can it will The in Section be weakened third will restriction The have fourth the form 6, but is undoubtfuture. A that in that is to be
The edly
simplifies It is hoped
stronger
in the
ensures shown
of sequence the
restriction
optimizable
sequence
expression that
divide-and-conquer cluster, in the lock top-level into The two pipelinstep, one data non-
to pipeline by simply
If an opt imizable be achieved at a time. element flow overlapping as a whole separately tion of the the The because simple. single
expression
always
expression
fashion.
subexpression subexpression
when
destination
to read
computed
by it.
at ions there
discussed
in the that
following every
sections,
the
preorder (Note
is implicitly
predefine )
procedure procedure. Whenever used satisfied, are fatal the static to take
is preorder
to define procedures
6 are
pression
implementation,
that
as is and However,
optimization. is significantly restriction virtues unlikely sequence stored and then of this to violate procedure
is straightforward
approach
worrying
fix any expressions are enhanced of the then restrictions. the any
approach
fact
expressions sequence
in an expression
are not
in variables,
on-line
be violated.
Languages and Systems, Vol. 13, No. 1, January 1991
on Programmmg
Automabc Transformation
65
{)ScanFilet
CollectMax
/ ~I
Fig.
5.
Thesequence
expression
in NormalizedMaxA.
restriction For
be fixed
by using
code the
copycan call be on
inst ante,
program
Normal izedMax
breaks 5).
the
expression
one that
(see Figure
function NormalizedMaxA (var Data: FileOfReal) : Real; var ScaledVals: series of Real; Sum: Real; begin (Data)); sum := CollectSum(ScanFile ScaledVals := MapFn(/, ScanFile(Data), Series(Sum)); NormalizedMaxA := CollectMax(ScaledVals) end It would with It For be possible cycle leave the to automatically restriction. it up to the However, introduce this code copying to resolve conflicts
the on-line to
is better example,
programmer can
procedure that
be brought
compliance
by realizing commute
ofcomputing
the maximum
and dividing
as shown
function NormalizedMaxB (var Data: FileOfReal): series of Real; var Vals: begin Vals := ScanFile(Data); NormalizedMaxB := CollectMax(Vals)/CollectSum(Vals) end This presented expressions expression accurate example here. are brings This up unimportant goal isto and make which given secondary it easy are that not. this what It goal would
underlying be better
the to
forprogrammers
toreliably
efficient
efficient. information
However, in order
is not to do.
possible,
programmers
to decide
to Restrictions
restrictions was present The first are the in some result of research looping formal is presented
Languages and
going on the
back
thirteen as opappears
concept
of representing attempt
common tostatea
of the earliest
Programmers
intermediate
ACM Transactions
set of restrictions
on Programming
Systems.
1, January
1991.
66
Richard C. Waters
are
implicit
in
all
the
on
restrictions explicitly
are typically stated. [41]. presented in a different his restrictions situation where sequence one here here, The
being from
other
research ways.
Wadlers
First, more
presented
they way.
are needlessly
he uses his restrictions motivation addresses with procedure they here. and effect behind the only
a single
be straightforwardly expressions, used The from more the in which than once. to
are not
to more implicit
statically-analyzable,
expressions
is no
However, no output
only
be used
is signifidata-flow cyeven
limiting. it is often
off-line expression
non-directed very
however,
beyond
this
all non-directed
data-flow efficiently
t bough It
is an overly
severe and
restriction. to
require
ever y intermediate
value explicitly
(i.e.,
order listless)
that, dure the putat the t ure First, limits have ate they oping is more being These operate term Wadler ions
to the
preorder
as discussed
subsection,
sequence
a bounded by itself
definition where
is different data
background (lists)
be optimized.
14 in the approach
reasons.
cannot
represent
sequences,
be expressed. of associated their to Third, that were intended from using the lists intended efficient create
could
perspective
sequence a new
Develapproach
purpose. error
are to achieve
reported
to be optimizable. vectors
programmers
can benefit
without
in standard
2.8 Avoiding
Wadlers expressions work
Unnecessary Storage
and the ly. work presented the here basic
Systems,
share
the
goal
of evaluating two
sequence is
efficient
However,
framework
Vol.
of the
approaches
13, No 1, January
1991,
Automatic Transformahon
different, has been Consider ~ is applied .T and Y(g(x) object because achieved. again the basic situation computed as efficient inefficient, value of ~(x). presented (i.e., 7 they use different
evaluation
67
methods
F(~(z)),
where
to a sequence
of evaluating sequence
here
basic
to be preorder).
to use preorder
less efficient.
algorithms
at compile
a joint
creation
of an intermediate
e sequence. is really
A key question
in both
approaches ~(~(x))?
if >oG zero.
computation
associated
~ to the computation
associated ~, this
is reduced
70~(x)
imply
be preorder,
to be much
problem
with in
preorder a way
consider sequence,
Reversal elements
reads the
the of
beginning
with it
first.
procedure Since
any
preorder. in order
and
outputs
of reverse the
elements
itself
the buffering
of inputs
sequence
In the expression tal ion 7 efficient is merely 7. While Wadler He over requires and it violates must than this the uses that the above moved 7(G
then 30~
the preorder (x) by cannot elements definition as his input test and that
tol
be so much
computed
G to a buffer
storage
to represent in length,
sequences
are potentially
guarantees
Systems,
an intermediate
13, No. 1, January 1991
68
Richard C. Waters
sequence shows amount guaranteed An beyond ruling a buffer storage The somewhat procedure very if .F for both 3
is not if
being an
created
the
The
central
in [41]
that
to
the
preorder
of internal internal
bounded
physical
representation of the
elements
sequence internal
inside
bounded has
restriction biggest
loophole, storage
a number
of
disadvantages. is that point. restriction a preorder 7. This is really sequence only that F in beside 7 question is whether counterpart uses bounded then use bounded if In this likely unbounded situation, not,
weakly
uses unbounded less efficient. to cases, be T Y, rather additional much could because than way problem to
it is virtually
is much
it is still
possible
Further,
to outlaw inherent An
expensive internal
engendered
being with,
is no practical no useful bounded out Iawed. cedures as their Given ability storage confined cient and users way
whether many
sequence common
of using Draconian
if given
have not
problems
it causes
it was better
in the interest
procedures
(see Section
preventing
are useful.
3. SERIES EXPRESSIONS
Vectors, series lists, data type and other such data structures and in the differ range that for in how closely full they model the The for the efficiency. a pre-
mat hematical mathematical As illustrated added to any processor Informally in length. remainder
embodies
a wide
be straightforwardly using
like
vectors
presents
an illustrative an in depth
selection discussion
functions.
Automatic Transformation
properties two ming sections of many present of these functions
The
69
next
when
procedures
implementing
program-
languages. lowercase letters (r, x) denote letters a literal : R denotes (F, series the arbitrary 7) denote containing series values, functions the formed by uppercase letters
(a, y, . . . . z) denotes The front can series, series kinds the Other
elements
so on element
series
Re.g.,
into compute Some three
6: (7,8)
series
Series series
non-
values,
transstructhe
ducers compute
There ture series from series are two cent aining elements. the elements
from
of collectors.
collectors for
create
an aggregate table
elements collectors
a hash
containing by some
a summary their
formula of can
of a series,
instance,
supports to define
be used
as arguThe to be a of
as the F,
argument
which
is used
successive value
(Typically,
of .?_.) The
is returned
computes fi, F,
the ())
of a series.
collection(z, collection(.z,
r : R)
(fi(.z, =
r), 6
Y,
R)
A xv.
of scanners.
Some
create
in an aggregate Other powers However, to define The element is used The should scanners of
a series
formula, at ion of
Lisp
implement
15 scanners. can
scanning, value z,
first
of the
third end.
P, which the
series
), and
up to but
not
including in length.
satisfying computes
satisfies
is unbounded
()
{
z : scanning Az..zs1OO) than wide collectors for classes (~(.z), = 3, P)
otherwise
Az.
z+z,
(1,2,4,8,
or scanners. the rest.
16,32,64)
In particular, four there key
more that
transducer transducers
as a basis
Nevertheless, transduction
of common
operations.
1991.
70
Richard C. Waters
that of the
it returns output
results, length
of partial
sums.
collecting collecting(z,
r : R)
r),
.F,
R)
function
is mapping, of the
which results.
maps Each
a funct element
ion of The
some
of series, output
a series as the
output length
is computed
by applying is the
Y to the
elements shortest
of the input.
inputs.
example
adds
corresponding . . . . (),
in two
. . . . rn : Rn)
.z+y, by
= .F(rl,
(1,2,3), testing as soon
. . . . rn) : mapping
(4, 5,6,7)) = with
(~,
RI,
. . . . Rn)
each
element
remaining The
elements
satisfying first
predicate element.
is encountered.
example
truncates ()) = ()
a series
negative
r : R)
() { r : truncating
(0,3,2, 7, that (~,
if P(r)
R)
=
.x<O,
1, l)) satisfy
a predicate.
negative
choosing(~, choosing(T, choosing(~z. Mingling icate. will element The from combines comparison two two
r : choosing(~, { choosing(~,
(0,3,2, one not 7, under ordered 1, l)) the to l?)
l?)
if T(r) otherwise
= control
(7,
1) predthe the
into are
ensure
combination shows
be stableif of two
by the result.
comparison
R precedes
sorted
result.
combination
a sorted
R r : mingling(R, {
s : mingling(r Axy. x<y) above, s : S, P) : R, S, P) = (1,2,3,4, some other if 1P(s, otherwise 5,7) transducers are r)
s : S, P)
=
(2,4,5),
transducers
ACM Trmsact,cns on Programming Lmgua~es and Systems, Vol. 13, NrI. 1, January 1991
Automatic Transformation
import ant as well. Catenating catenating catenating(r catenating((6, Spreading integers of S. copies copies In the is a quasi-inverse a series the ith output, appends (), : R, S)
71
S) = r : catenating(R,
(9, 10)) = (6,7,8,9, takes out ith
7, 8),
of choosing. S, and
Spreading creates
R and
of values elements
a series
by interspersing
element with
element of choosing,
together
example
illustrates
between S, z) (), z)
spreading.
spreading(r
: R,
s : S, z) = _
r copies
: s : spreading(R,
S, z)
spreading((3, Sectioning begins the n input input, extracts with element the creates the indexed out put
1),
(7,
l),
O) =
(0,0,0, of its
7,0, series
1) input. the length The not index The subseries including O.) Th~ series example
a subseries indexed
element
continues
up to but the
in a series-has out
is optional. a section
to be less than
of the
of elements.
sectioning sectioning(R, sectioning(r sectioning(r sectioning((l, The more function than one chunking output. of widt manner
O) =
: R, O, n) : R, m,
= r : sectioning(R,
n) = sectioning(l?,
2, 5) the of ones
above,
R into
if R =
chunks in the
h w >0.
Successive window.
of a moving
element etc.
of the is
number where
of chunks
output)
( IRI w)ldj,
\Rl denotes
R.
= () d, sectioning(R, dl))
d, r : R) d, R)
= r : chunking(l, = S1,
. . . . SW where d, sectioning(R,
Languages and
Sk = chunking(l,
ACM TransactIons on Programming
kl,
Systems, Vol.
lRl+kw))
13, No. 1, January 1991.
72
Richard C. Waters
chunking(2, mapping(~xy. By itself, chunking with (z+y)/2, may other appear (1,5,
= =
(5,3,7)
somewhat For
it
is quite of the
useful example
how the results (Programming the outputs list can preceding that
be viewed
as a recommendation in conjunction (e.g., none APL) with support contain. elements vectors
kind data
of functions type. The it does value In are not efficiently ruled out the elements as on-line (The only mingling, 4,
a sequence most
functions;
accessing the
reflects includes
to be used
that
rearrange
the order
of
opt imizable )
off-line
implementations
sectioning,
chunking.
A COMMON
Eeries can be
LISP IMPLEMENTATION
added of the into series essentially data any programming and defining language by adding an supcan both has structure 3. The a macro and a set of procedures of series Such expressions that package
functions easy
in Section to do using
optimization 6). package. is generally series a data the a second series the runs and
be supported in regular In
of Lisp,
a macro
Series.
using part data The
implementation, has 30] a procedural capable are computed accessed data part
unoptimized part so far. using of the time series The the scheme and
part.
is a generator elements
of computing
elements
of a series
generator
enumerates part it returns argument The puted access is used The it is not implement
ACM
in the
to compute
Each
needed, the
those [20].
Figure
6 illustrates
structures. of series
is effective expended
on producing is on the
1,
at ion,
focus
expressions
Vol 13, No.
Transactmns
on Programmmg
Languages
Systems,
January 1991
73
(+ x 1))
(funcall
at-end)))))) of a series.
; Returns agenerator fortheelements (defun generator (s) (let ((g (car s))) #(lambda (at-end) (when (null (cdr s)) (setf (cdr s) (block nil (liet (funcall g #(lambda () (return (if (not (eq (cdr s) T)) (car (setqs (ccir s))) (funcall at-end))))) ofchoosing(P, (defun choose-if (p s) ; Implementation (let ((gen (generator s))) (list #(lambda (end-action) (1OOP (let ((x (funcall gen end-action))) (if (funcall p x) (return)))))))) (defun (let ofcollection(O, collect-sum (s) ; Implementation ((gen (generator s)) (sum o)) (loop (let ((x (funcall gen #(lambda () (return (setqsnm (+snm x)))))) (choose-if
6. Illustration of
T)))))))
S).
~z~.z+y,
S).
sum)))))
(collect-sum
Fig.
ttoddp
the Lisp
first5))
implementation
9
of unoptimized series.
they In
the
physical
representation it is usually
of series better to
altogether. represent a
is impossible, as a series.
sequence The
as a vector
protocol
for obtaining
an accessing
generator
of a series implementation.
and
is important
inthe
of optimizability
analyzability
Series procedures.
by Lisp #z(z y procedures
as shownin
character
z) is provided
reading
(catenate #Z(l 2) (choose-if #ockip (subseries (mingle #Z(l 5 9) #Z(2 6 (multiple-value-bind (XS ys) (chunk (map-fn T #(lambda (x y) (/ (+ x The cating, ments effect The ning. tial The higher-order and and collection produce given and procedures are multiple situation. always illustrate implementing so that (Series values. However, more the
#Z(8 -7 -6 l))) = #Z(l 2 -7 8) #i) 2 4) * #Z(5 6) 2 1 #Z(l 5 3 7)) y) 2)) xs ys)) ~ #Z(3 4 5) scanning, they oftuples multiple than procedure stepping using can collecting, accept could series scan-fn, procedure numbers state values
and
1)
mapping, series get the is usually supports and two oftheir Each
13, No.
extended
multiple
in any
convenient
almost below
efficient
tuples.)
examples
example, scanning
are returned
natural
twointernal
must
accept
as many
as it returns.
Systems, Vol.
Transactions
on Programming
Languages
1, January
74
Richard C. Waters
Series collection(z,
Lisp
Implementation
type type
type T P F
2 f
type
Y ?)
Z
RI
F
R,, ) Rl R,n)
scanning(zi
collecting(z,
~i
7.
7)
R)
(scsr-fn
(collecting-fn (map-fn (until-lf (choose-If
mapping(>,
trlmrating(~,
RI.
l?)
., ,, R,n)
R1 R.) R)
R.)
Rl
choosing(~, mingling(R,
catenating(R,
R) S, P)
S)
(mingle
(catenate
spreading(R, sectioning(l?,
chunking(u,
S, z) m,
d,
n) R)
Fig.
values
state ()
1)
Integer Integer) () (values 1 1)) (1 i sum) (+ i 1)) (values 3610 1 ...) (+ sum i)))
-#Z(1234.
..)and#Z(l
Three introduced, procedure. to ensure determined that values is the second scan-fn. As
other
features
of note.
First,
anew returned
first
argument stepping
is
bythe
this
argument
is necessary canbe
stepping is replaced
procedure by
time. values.
a procedure initial it and as adrepeator string, creates the to be first as well Omitting The
inconvenient that
multiple
Third,
a predicate
extensions a convenience
map-+n
user,
include: which
scan
in a list, scan-pllst
in a range, along
of the
indicators values.
in a property
a second the
series type
argument defaults
If omitted,
type
(series test) * #Z(test test test, (scan (a b c)) ~ #Z(a b c) (scau vector #(a b c)) + #Z(a b c) #\U #\Z) llTu~tl) > #Z(#\T (scan string (scan-range :from 1 :upto 3) ?tZ(l 2 3) (Scan-pllst (a 1 b 2)) #Z(ab) and ttZ(l similarly, combines adds up elements the the anumber elements elements of specific of a series of and a series, collect-first collectors into a list, which
or string, the
collect-sum element
collect-length
number
in a series,
ACM Transactions on Programming Lan~a~es and Systems. Vol. 13, No. l, January 1991,
Automatic Transformation
(or nil object if the series is empty). The first the
type
75
of
to be produced.
If omitted,
type
defaults
(collect #Z(a b c)) * (collect simple-vector (collect >string #Z(#\T (collect-sum #Z(l 3 2)) (collect-length #Z(fee (collect-first #Z(fee (collect-first #Z()) * Finally, (based inserting (based respond choose-if) only a number
(a b c) #Z(a b c)) > #(a b c) #\u #\z) ) 5- Tuz ~ 6 fi fo fum)) + 4 fi fo fum)) * fee nil transducers takes the first in a series front and elements argument, non-null of the non-null are and of its and provided shifts including: it over the second elements of this last previous by coron
discarding
choose
positions
returns choose
If given
one argument,
returns
the
elements
(previous #Z(fee fi (choose #Z(Tnil T) #Z(l (choose #Z(nll 3 4nll)) (positions (rnap-fn#oclcip
fo fum) !! r!) > #z(!! r, l,fee,, 2 3)) +- #Z(l 3) =%- #Z(3 4) #Z(l 2 3 5 6 8))) * #Z(O 2 3) In cognizance provides The maps that .F. #Z(4 the 16)) * tlZ(2 4) three #macro ofthe ubiquitous that syntax
,,fo,,)
Convenient
ping, the Lisp to express a procedure (#Msqrt The over the form
support
series
formapping.
implementation kindsof mapping.
nature make
ofmapit easy
mechanisms character
#M~converts
T t#sqrt specify
mapping a literal
of a complex lambda
computation It has
series
having For
to write
expression.
syntax
example,
((x (abs as
(scan (2 X) 3)) *
(map-fn
(x)
(expt
*
(abs
#Z(8
X)
3))
-2
3)))
8 27)
The returned.
form
is the
same
as mapping
except
that
the
value
nil
is always
(iterate ((x (if (plusp To a first mapc ar. the body lazy than
(scan (2 x) (prinl
nil
23. inthe for same its result. iterate series wayasmapc However, and and where due where are
mapc, iterate
is intended
to be used
in situations
evaluation
of series,
difference If mapping
mapping
of efllciency.
in a situation elements
ifi performed,
loops.
equivalent procedure
loop over
is expressed a series.
by This
simply is typically
using done
series
expression
ACM Transactions
on Pmgrammmg
76
Richard C. Waters
(defun
bset->list
(collect
(choose
:from
O)
(series
bset))
(defun
list->bset (items universe) (collect-fn integer # (lambda () O) #~logior (mapping ((item (scan items))) (ash 1 (bIt-position iternunlverse))))) bit-position (item (nconc Fig. 8. universe) universe Converting (#Meq (list between (series item) item)))))) hsts and bit sets. (scan urnverse))))
(defun
(or
(collect-first
(1(length
(positions
using
mapping.
In the
example,
a list
ofsums
is computed
based
on a list
of lists
of
numbers.
2 3) (45 6) (78)))) (let ((data ((1 (collect (mappmg ((number-list (scan data))) (collect-sum (scan number-list)))))
+ by the and
(6
User-defined
mappmg new tion below, series
series procedures.
the standard Lisp However, defined
definitions defmacro
procedures.
series No
macro
package This
a series defmacro.
procedure
is being
with
defun. special
is done
by using is required
optimizable-series-function.
declaration
(defun
collect-sum
(numbers) () O) #+ ) numbers))
(declare (collect-fn
(clefmacro mapping (var-value-pair-list &body body) (let* ((pairs (scan var-value-pair-llst)) (arg-llst (collect (#Mcar pairs))) (value-llst (collect (#Mcadr pares)))) (map-fn T #(lambda ,arg-list ,@ body) ,@ value-llst)))
Example.
in a realistic procedures packed of sets. Sets where sented used to over each into
The
following
example context.
shows The
what example
between and
agraph can
uses the
universe integer
very
as binary Here,
represents
an element
as binary manipulate
litsets.
operations loglor on integers the ,which computes union of two and bit bit
sets represented
aslists between
has to reestablished
positions
is a list
of elements.
a bit
set
in u is in the
on Programming
A universe is specified by a universe. b is associated with a universe u, then set represented by b if and only if the ith bit in b mapping integer
and Systems, Vol. 13, N0. l, January 1991
Transactions
Lan~ages
Automatic Transformation
77
) O) #loglor
bsets))
-1)
) #logand
bsets))
sets.
on series of bit
is 1. the
For set
the
universe Lisp
the
#bOIOll
Common its
the
an integer
associated along
procedure It and
set into
as a list
elements. positions
integer counts
argument
into the
a bit bit
set created.
procedure 1. The
to determine create combine The position depending procedure the universe. Iftheitem onto the is done Figure The first the
an integer
setto to the
to the
bit-position to or
an item The
corresponding on whether
procedure is in the
of two line
ways of the
item
contains If the is not end of the by side effect 9showsthe procedure the
expression in the
that
item
in
is not
universe, second
expression
the
the
item
returns oftwo
universe sets.
definition computes
operate of bit
onseries while
computes
intersection.
Live variable
sider the as blocks part block
analysis.
Asanillustration that
of the
way
bit
be used,
con-
following.
Suppose
in a compiler, by
program possibly
represented The pieces top Each of to. these about that (i.e., the are field because
1991.
code the
control ablockof
flow.
of Figure Bhasseveral
data that
represents
code.
ofinformation as a list
Twoofthese other
information A program fields. In addition the read that way written (computed are live by without
to B and point
blocks
B can branch
through
of blocks
flow and
accessed.
either
written procedure
or read
additional
determine-l~ve
discussed
records
variables
(A variable
if it has to be saved,
Systems, Vol. 13, No.
on Programming
Languages
1, January
78
Richard C. Waters
(:conc-name nil)) ;Blocks that can branch to this one. ;Blocks this one can branch to. ;Variables written in the block. ;Variables read before written in the block ;Variables that must be available at exit. ;Temporary storage location.
(defun determine-live (prograwgraph) (let ((universe (list nil))) (convert-to-bsets program-graph (perform-relaxation program-graph) (convert-frori-bsets progra-graph program-graph) (clefstruct (tetnp-lxets used written live) (:conc-name
universe) universe))
lxet-))
(defun convert-to-bsets (program-graph universe) (iterate ((block (scan program-graph))) (setf (temp block) (make-temp-bsets :used (list->bset (used block) universe) :wrltten (list->bset (written block) universe) :llve O)))) (defun perform-relaxation (program-graph) (let ((to-do program-graph)) (loop (when (null to-do) (return (values))) (let* ((block (pop to-do)) (estimate (live-estimate block))) (when (not (= estimate (bset-live (temp block)))) (setf (bset-live (temp block)) estimate) (iterate ((prev (scan (predecessors block)))) (pushnew prev to-do))))))) (defun live-estimate (block) (collect-logior (mapping ((next (scan (successors block)))) (logior (bset-used (temp next)) (loganclcz (bset-live (ternp next)) (bset-written (temp next))))))) (defun convert-from-bsets (program-graph (iterate ((block (scan program-graph))) (setf (live block) (lxset->llst (bset-live (temp (setf (temp block) nil)))
Fig. lo.
Live variable
un,verse)
block))
universe))
analysis
it
can
be
used with
by by the
Finally,
there
is a temporary that which that are bit uses perform givena live in sets.
data The
involved
10 shows this
represent To
ed as a list
block. procedure
operates
in three
(convert-to-bsets)
looksat
each block
containing
set representations
ACM TransactIons on Programmm~ Languages and S~stems,Vol. 13, No. 1, January 1991
Automatic Transformation
for the written in the second variables, This auxiliary temp field step (perf the used
79
are no 10 and
variables, The
is defined
in Figure an empty
bit
variables variables
The
until
answer
rom-bsets) bit
operates
step.
Each
is converted to determine
in the
On each cycle whether the to it the minus bit the sets.) successors
in perform-relaxation, To do this Each that variables procedure are plus of the inspected. the (The
its live set has to be changed. of the block it writes. estimate variables variables A new it uses,
logandc2
total
set of variables
by the
successors
by using
collect-logior. from the In that new This there. current addition, estimate if the of what variables is changed, current block block requires onto stop
is different
estimate
perform-relaxation will their the be examined live list estimates unless comput Figure to
adding
predecessor of liveness
to-do the
as the
estimates
changing,
Summary.
sions are opt imizable. computations cient ly using
of the the
way
series
expresare
intended
series
expressions
Second, that
operations
is done, into
it from
two
or more
fragments. to renimproved
expressions rather
are not
intended
programs expressing
entirely the
to provide
a greatly
method 5.
of loops.
A PASCAL IMPLEMENTATION
can be added system to Pascal has been in in much Lisp rather error the ed that than is issued same way Pascal as they and are added this only [29, 46]. supports to Lisp. However, optimizis blocked. this still A construct demonstrates whenever Lisp
prototype series
prototype
is written expressions.
optimization implementation,
Although allows
approach
of the series
Series. The
ogy with
type
supports below.
array
var In line
Integer;
of
philosophy type.
elements of its
1991.
of a series
the
However,
of a series
part
1, January
80
Richard C. Waters
Pascal CollectFn(z,
Implementation >, R)
R) T) .,. , I?n)
.F, R)
P) >,
R) R,) R) , Rn)
R) S, T) S) S, z) n, m) d, R) 11. Pascal
S, S, (R, d,
7) S) z) n, R, m) S1, . . . Sm)
type.
This
is important
to length. The
facilitate
the
definition
of series
procedures
operating
on series
of arbitrary
Series procedures.
by Pascal the (e.g., not same procedures names linked the becomes to
series
3 are
all
Pascal show
as the an
corresponding
scan-fn support
of names
implementation
of series. ) returns
concept
of a function into
multiple
out puts
of chunking ((l,2),
(Mlngle((l 1, (1,5,3,7),
<), Xs
MapFn(Average, Xs, Ys) function Average (x,y: begin Average := (x+y) div end; (Since the syntax the Pascal
Integer;
does in the
not
provide
literals, while
from for
Section literal
examples
in this
a notation Iittle The their the Since, method The parameters they in
series
in small the Given without of multiple need the for usual allow
obtain support
to be employed in Figure
tuples. restrictions number in the any the not of arguments types oftheir generic and any being
procedures
receiveto
is important
because
applicable
aslongas generic
be implemented they
asuser-defined
ACM Transactions
procedures
on Programming
in Pascal.
Lan~agss
asanextension
Vol 13, N0. l, January
to the language,
1991.
Automatic Transformation
do not violate the spirit of Pascal. the same most
81
allow than
and
type
a more least
would
be possible
higher-order
functions
as user-defined
procedures. All tation as well. arguments. not lists. of the that specific are scanners, to collectors, Pascal in but are and transducers by and these the from the Lisp implemen-
Pascal
Given
Collect functions
Since In keeping
of Pascal, than
collect returning
takes
the
destination value.
as its * ~ 3) (T,
first
an aggregate
. ..)
Tuz 4 fum
in
X.
,3,2)) (( fee,
none) fi,fo
(>
, ,~fee>,
>fi),
]fo~ )
Choose((true,false,true), Positions(MapFn(Odd,
=$=- (0,2,3) syntactic tothe that extensions, Lisp the Pascal mapping even implementaand more iterate. useful. mapped Sqr is autoset.
Implicit
tiondoes However, Whenever over the matically
mapping.
not it support supports
forms
is in
many
ways
of the
CollectSum(Sqr(Scan( [2,41))) = CollectSum(MapFn(Sqr, The key virtue that on the of implicit have previous and to be
* it
instance, the
example instead
a moving
a
write it.
following
of defining
Average 1,
mapping Ys);
(Xe+Ys)
div
2 * separate
(3,4,5) from easily the be other dispensed that concepts with. support is being
mapping expressions.
associated
with asshown
could the
other
mapping Lisp
(Although
thelack
compile-time
information to the
a number
of complications,
mapping
User-defined
dures in Pascal
series procedures.
are simply procedures
As
shown that
in the
examples series
below, inputs
series or return
proceseries
either
have
ACM Transactions
on Programming
82
values.
.
As
Richard C. Waters
with series in general, all such definitions kind are handled directly Pascal by the does not
isnoneed of macros.
foranyspecial
of declaration.
Example. used
how
series
expressions
can
best
be The
example operating to a chain of fields type type type type There procedures a job queue, the
an
basic
type
definitions
of jobs.
to a descriptive
including
JobQ = JobQentry; JobQentry = record; Job = JobRecord; JobRecord = record are a number include a queue
JobInfo: Priority:
Rest:
on job below) To
queues. and
onto end
from
the anew
add itto
a job the
one merely
to allocate
queue
entry
andattach
(J:
Job;
var
Q: JobQ);
end In define as with out addition a number any that to ordinary of series data job convert have Q-.Rest, using operating procedures procedures structure, queues that that operate operate ofjobs on job on job to have and that queues, queues. procedures vice versa. enumerates below, scani% it In It is useful particular, and turns tails of also to
aggregate
CollectJobQ
a procedure Q-.Rest-
a queue
AS shown procedure
function ScanJobQtails (Q: JobQ): series of JobQ; function JobQrest (Q: JobQ): JobQ; begin JobQrest := Q-.Rest end; function JobQnull (Q: JobQ): Boolean; begin JobQnull := Q=nil end; begin ScanJobQtails := ScanFn(Q, JobQrest, JobQnull) end Among below. over ing apointer the job other The things, ScanJobQtails ScanJobQtails(Q) the Joblnfo returned can be used .JobInfo field ofa to implement causes JobQentry the ScanJobQ operations asshown of followmapped
selecting pointers
to be implicitly
and
Systems,
Vol.
13, No,
l, January
1991,
Automatic Transformation
The procedure using the to the is returned one job queue tails last RemoveFromJobq ScanJobQtails of the and as the next queue to last removes
83
It can be
below.
entries
in the
is assumed to last
in the
in order is then
(If there
is no next
is set to nil.)
associated
function RemoveFromJobQ (var Q: JobQ) : Job; var Qs: series of JobQ; NextToLast, Last: JobQ; begin Qs := ScanJobQtalls(Q); Last := CollectLast(Qs, nil); NextToLast := CollectLast(Previous(Qs, nil), := Last.JobInfo; RemoveFromJobQ if NextToLast=nll then Q := nil else NextToLast.Rest := nil; dispose(Last) end The while first the three statements in the body in the be noted
nil);
form
a series
eficiency queue As
since into
is converted optimizable
example
procedure last is no sion viation series returns cause (i.e., such that of the the darddeviations
returns twostan-
in the
than queue.
priority
jobsin
last have
statements large be
expression
the begin
queue the
scanned deviation
after
computed. function SuperJob (Q: JobQ): Job; var Jobs, SuperJobs: series of Job; N: Integer; Mean, SecondMoment, Deviation, Limit: begin Jobs := ScanJobQ(Q); N := CollectLength(Jobs); Mean := CollectSum(Jobs.Priority)/N; SecondMoment := CollectSum(Sqr(Jobs.Priority))/N; Deviation := Sqrt(SecondMoment-sqr(Mean) Limit := Mean+2*Deviation; Jobs := ScanJobQ(Q); := Choose(Jobs .Priority>Limit, SuperJobs := CollectLast(SuperJobs, nil) SuperJob end
ACM Transactions on Programming
Real;
);
Jobs);
84
The
Richard C. Waters
above are a good with, the that all example of the way series expressions are intended This vast simple
programs
of the in
programs of series
primary are
goal fact
of programs
a program having
it in a loopexpressions.
without
ALGORITHMS extension
them into node
or compiler
converts into this
that transforms
stages: equivalent representing data
optimizable
which graphs, flow
series locates
be implemented
in three
parsing
pipelining
and inserts the
loop,
unparsing
code in
appropriate
program
is used same
illustration. the
The
implementation
way,
characteris-
of Lisp
simplify When
stages. to a program, the static it begins types by of the parsing procey and
Parsing.
the dures program. called
Series by the
expressions program.
is being
analyzability reported.
straight-line
are checked
violations type
complete
information non-series
is availproceuse
where
are applied
to series.
application
is replaced
by an appropriate
of MapFn. The to each final action of the series parsing stage is to create located. to do. the variables a data each flow graph corresponding expressions becomes the is a a node way the
optimizable
of these call
procedure is derived
between way
from
procedure
calls
are used. is illustrated computes the loop code the 5). the shown in Figure sum of the fact uses not 12. The squares that is quite more to lead it
Pipelining.
series expression of the odd
of the
pipelining SumSqrs
procedure readability
elements
of a vector)
in the procedure
SumSqrsPipelined. contains efficient. variables inefficiency is available. The conquer for While Once a single flow pipelining strategy doing this, a number The than
variables.
code
is that Reeult
strictly
during
optimizations the data divide flow on-line and graph ports. cycle into data series
operates clusters
2.5 is used
a series
expression
on-line
pipeliner is complete,
rest rict ion. partitioning procedure. the procedures the are combined based process, on the each The resulting procedures To support are then combined
between
subexpressions.
combination
ACM Transactions on Programmmg Languagesand Systems, Vol 13, No. 1, January 1991.
Automatic Transformation
85
function SumSqrs (V: array [1. .N1 of begin SumSqrs := CollectSum(Sqr(ChooseIf(Odd, end
Scan(V))))
(V:
array
[1..NI Sum2:
of
Integer):
Integer;
Result5,
Integer;
sum2 := o;
:= l+Index15; Index15 if Index15>N then goto O; Element12 := V[Index15]; if not 0dd(Element12) then Result5 := Sqr(Element12); sum2 := Sum2+Result5; goto 1; := Sum2 o: SumSqrsPipelined end 1:
goto
1;
[11
-- Scan of a vector
inputsoutputsvarsprologbody-
---------------------------------
[A..LI of ElementType; Vector: array Element: Series of ElementType; Index: Integer; l-K; Index: Index := I+Index; if Index>L then goto O; Element := Vector[Index];
[2]
--
ChooseIf inputs-
----------------------------------------Boolean; function P(X: ElementType): Item: Series of ElementTbype; Item: Series of E1ementType;
2;
outputslabelsbody-
2:
then
goto
2;
[3]
--
Implicit inputsoutputsbody-
mapping
of
Sqr __________________________
[4]
--
coll~cts~ inputsoutputsprologbody-
ElementType;
sum := o;
Sum := Sum+Number; Transforming
Transactions
Fig. 12.
ACM
optimizable
on Programming
86
Richard C Waters
procedure
is represented Input Output Auxiliary Labels Statements Statements Statements part series in each to data procedures the output
as a loop
fragment
with
one or more
of the following
parts:
inputs outputs-
variables. variables. variables used by the that that that used by the comput the at ion. computation starts. computation. before executed. after fragments These from. flow ports. flow between on-line ports (e.g, the Sum), of Sqr to the input the various and labels The of Collect the loop that fragments in the Two left terminates. represent are hand on-line the procedures to crealone
vars labelsPrologbodyepilogThe called ate the which gorithms bottom by the loop fragment
numbers to data
indicate and
different
are used:
between
off-line
by data mapping
parts
fragments so that
are renamed the much of loop When input in the instance computed. algorithm the call fragment. evaluation procedures
is implemented same as the as an application [3].) procedures data the form two that rather process flow fragment Next In, fragments the body than
variable (The
so that
it is the the same fusion two figure), of the The except on NextIn, (This [17].)
of the
source.
process
standard
compiler
optimization
data
flow
input
on-line
source
concatenated compiles
essentially
Unparsing.
the into The into series outputs the a loop
The
result
loop
to
expression
as a whole.
stage, code
up to the loop.
original
expression.
other
of the
fragment
O, 1, Iabek;
vars;
prolog ; 1:
body;
1;
series
expression Pascal
replaced
by a loop,
the
resulting
code
can
be passed
ACM
to a standard
on Programming
Transactions
Languages
Systems,
Vol
13, No.
1, January
1991.
87
has in
above
verified
are
involved.
are implemented
4, then
the transformations as long output. transformed For code instance, motion lazy as they
of side-effects
a single
this is that
overall the
exactly the
lazy
evalu-
algorithm
involves
this
simply
moves
where
evaluation
series The
to be first seeks
computed. more formal at from compile the point of view in This of path a program analysis each can place [1 I]. lazy to determine and where in two time where
it will ways.
be reused. If there
information
of first
evaluation last
of lazy value
If there beyond
a value,
there for
of the
computation computation
of the of the
elements realize
place
storage. one should makes will be. side-effects are still to figure problemout what func-
be readily
understood.
element if ~
input, with
then itself
temporal cent aining does More 6.1 The years. Lets Lisp. The not
interacts X via
environment input
expression with
(e.g., result
by doing
interact
anything
else in X,
is easy enough
to understand.
complex
uses of side-effects
be avoided.
implementation
implementation
in portable
same
basic
approach
independently question sequence compilers A quite ever, from rather series. series than can [12].
developed be eliminated.
of restrictions
that
every
about
optimizing
similar
is also particular,
used it
internally Loop
by the macro
Loop
macro English-like
[13].
Howsyntax on
as discussed
section,
the
is externally of procedures
very
different
expressions. representing
uses an idiosyncratic
computations
as compositions
operating
13, No.
1, January
1991.
88
Richard C. Waters
7, COMPARISONS
There with are related two primary concepts. vantage The From most with view this of the a few series points from which comparison the key to compare is with feature by the and are being series other of series vector expressions support for expressions operations operations continuation reuse of loop taken of series variety presents Each definition It also of of of
most
[32], the
operations
the more
stream
additional expressions
efficient. the
way
a logical
trend
fragments. by iterators
approach feature
context the
is that
they above,
support the
reuse
a wider section
are easier
and modify,
without
example sum
example elements
of a procedure illustrates
procedure
be defined.
function SumPositive (V: arrav [1. .N1 of Integer) : Integer: function Positive (X: Integ~r) : Boolean; begin Positive : = X>O end; begin SumPositlve := CollectSum (Choose If(Posltive, Scan v))) end function CollectSum (S: series of Integer) begin CollectSum := CollectFn(O, +, S) end : Integer
programming comparisons
not
be practical
one of these
used
APL
approach are
is in
APL
evolved between
expressions 13.
to
used
of loops.
correspondence operators
operations
series
functions
discussed The
implicit APL
Section
of
APL
is summarized
to vectors
concept mapping.
the
As illustrated quence
rect ly
below, can
both
the
vector
summation represented
algorithm in APL.
an explicit
and
Since scan
user-defined
sequences operation. are
sedi-
procedures
represented ~ SUM= SUM+
be compactly
there
as vectors,
is no
need
for
[11 v ~ [11 7
NUMBERS
ACM Transactions
on Programmmg
Automatic Transformation
89
APL OperatiOn F/R missing F\R RI (((P F Rz R) L 1)1) TR scanning extension take compression catenation based on expansion take and drop I m. ~ R
name
reduction
scanning(z, collecting(~,
mapping(.F, truncating(P. choosing%, mingling(R,
2, ~) .F, R)
RI, R) R) S, T) . . . . Rn)
of scalar
operations
catenating(R,
spreading sectioning chunking(w, simple missing idioms (R, (R,
S)
S. z) m, d, R)
index generation,
reversal, rotation,
membership,
grade up/down,
inner product,
modifying
etc.
elements
Fig. 13.
The correspondence
The
between
APL and
series
expressions
are that
APL vectors
can-
the set of APL operations about could what have is efficient been
is somewhat and what in In initially operation. be one of the As a result, a small initial set identity
different, is not.
the
series support
supported
APL, addition,
there
is APL For
mingling, as well
or chunking. as it might
higher-order operator
appear.
reduction APL,
in standard
of a naming benefit
collectors. be implicit.)
collateral
of allowing
four
operations by series
(reversal, expressions,
grade they
up, cannot
and
grade
down)
a preorder modification has to rely operations. For first more always Explicitly
without elements
introducing
series
expressions, any
constructs
performing
of these
to
sort
in or not
the
Lisp
one
must
an intermediate
sorting
some
physical
representation capable
A few
compilers where
of producing
of As
series series
feedback
standard array
in APL
contrast,
while
it is possible
1, January
90
Richard C, Waters
R)
>,
F, RI,
P)
R)
type R
R1 P R) R S P) R type
R~)
T R))
truncating(~, choosing(P, R)
1?)
O (posltiOn-lf
(remove-if-not type
S) (concatenate
mingling(l?,
catenating(R,
S, P)
S, z)
m, n)
S)
sprearling(R,
sectiOning(R,
R m
rL)
d, R)
reverse, between
modifying
elements t~perations.
Thecnrrespondence
series functions
andsequence
there
are
no special but
series striking
operations difference
for
operating
on them, series
and
they and
are APL
optimized. a superficial expressions but between calling expressions while series use standard cryptic, subroutine notation APL uses a
Finally,
set of concise,
operators. While Lisp used are many instead (if not most ) Lisp programmers computuntil
Common
use loops ing recently, it
extensively, Lisp
where
intermediate
of loops.
supported defect
Lisp
was
this In tor.
suite
operations. Common However, Lisp The a list of these are not structures a complete the Figure in limited series Lisp to representing at ion functions does not and
sequences correspondence
implement
of mathematical support
between
operations
is summarized
example the
below vector
shows
Lisp and
sequence
to express Since
summation sequence,
a vector
is a Lisp
is no need
-not
(v) #pluSp
V)))
(defun collect-sum (nmnbers) (reduce #+ numbers) ) Except there operations. spreading, is specified a way that Current
ACM
for
the
fact why
that there
Lisp
unbounded scanning,
is no reason
all the
be supported
is no
value. As a result,
compilers
on Programming
do not
Languages
expressions.
1991
Transactions
Systems,
Automatic Transformation
timizable mization, As in APL, elements Lisp An port does series expressions surprising are that toward much Lisp
91
more
of opti-
it is not there
provides
no feedback and
is no bias It
preorder to
is also
common
sequences manipulating
any
special Lisp
aspect
of the
is that
sup-
arguments
behaviors.
example,
operation of the
count -if,
which
a predicate sequence
returns
number
of elements
that
(1
-2
3 4 -5)) takes
~ two
3 keyword of the : key can arguments input be in used : start which to and : end, is to access should is the by the necessary. The : key
count-if specify
a keyword be used
specify
to fetch Finally,
of each
sequence
element exists,
by the
an operation
as count-if
that example
values
returned
predicate. As illustrated The : start and and of these with is strictly subseq. complex : end keywords be dispensed with using
keyword
count-if-not
can be dispensed
by specifying
predicates.
(count-if-not ~ (count-if
#plusp ((1) (-2) (3) (4) (-k)) :start O :end 3 :key #car) # (lambda (element) (not (plusp (subseq ((1) (-2) (3) (4) (-5)) various options described subseq an above instead
(car element)))) O 3)) ~ 1 for two and ) reasons. : end keythey arguand
Nevertheless, First, words increase ments easier pression eliminates ping desired makes test y). and they
the
promote
(Using creates
intermediate
sequence.
Second,
predefine This
operations makes
of lambda
expressions.
Using
expressions, the
neither
of these does
comes
up.
In the
Lisp since
ex-
use of subseries creation to avoid is simply count - if of its the mapped itself The to
series. the
support (again
mapThe
expression.
and
without allows in
can be dispensed
a combination
collect-length. procedures
individual
be simpler
programs
appearance.
(let
( (elements
(collect-length
(subseries
(SC= ((l)
(#llnot
(-2) (3) (4) (-5))) o 3))) (#Mplusp (#Mcar elements)))))) ~ are the central technique and in data type
Seque.
language beginning The
Under Seque
[20].
basic
evaluation bounded
discussed Section
of Section
4, Seque between
unbounded
sequences. 3 and
correspondence
functions
discussed
ACM Transactions
on Programming
92
Richard C. Waters
Series Function
collection(z, scanning(zi collecting(z, mapping(>, >, >, F, R) P) 1?) Red(R,
Seque 7)
Operation
! Length(R)
Idioms
Red(R,
based
F)
on , Rn
! Z)
RI, R) R)
. . . . Rn)
[F(R1 R\\
[If [If
I z,
P(R
1 z)]
then ZI] ! 1
derived filtering
stream
truncating(p, choosing(P,
post-truncation
P(R
! ,)
then
R 1 ,]
mingling(f?,
catenating(l?, spreading(R, sect, ioning(R, chunking(w, simple missing Fig. 1.5. idioms
S, P)
S) S, z) m, d, R) n)
operations operations
provided
by Seque
is summarized of special
many
operations
both
summation ! equivalent
algorithm Since
user-defined
can be easily
represented
in Seque.
are a distinct
to Scan is required.
SumPositive CollectSmn(
lambda(e)
if
e>O then
e] )
procedure CollectSum L := Length(S) return if L=O then end Since all the lecting, because spreading, this unbounded series
sequences
are supported, However, when of the higher-order for defining stream collection
functions leads
in Seque.
or chunking. there
In addition,
is no specification support
also no direct impressive the the language series Seque eliminating series programmers use of assigning on efficiency. does
in Seque to note
Seque to
is based the
that
operations, the
operations evaluation
optimize efficient
a result,
expressions
to think
of streams
without
any regard
consequences
Summary.
principal the much
ACM
with
series
languages.
best
is efficient
1991.
what
Transactions
on Programmmg
Languages
1, January
Automatic Transformation
93
not.
As
part
they
make procedures
the
that
cannot the
be efficiently programmer to
by forcing
facilities
host
language.
7.2 Looping
The
Notations
virtues by the construct. of series discussion fact that complex More expressions in the in comparison of Section the allow use of only support equivalent forms which the with 1. looping However, the most several constructs this basic of the diskind feaand as a to
fundamental
beginning
by the
constructs
expressions. not
In particular,
dispersed
of integers.
languages
by providing based
Common
provides
a form
on scanning a relatively
range support
of the
oldest
concepts uses an by
analogous
constructs controversial.
of looping
fragments
analogous
to scanners
collectors.
utility below
Loop code
macro produced
macro
or less
produced approaches
when
optimizable efficient.
expressions
pipelined.
As a result,
are equally
(clefun snm-positive-loop-rnacro (loop for item being each when (plusp item) sum item) ) Loop example). mapped in the like supports A over example). Loop the call the a keyword on the values However, does not definition (which that
(v) vector-element
of
transducer fragments
an arbitrary any
computed the
by the
scanner-like
support
transducerfragments, it
looping
fragments. support the definition fragments. of the are quite parts of new collector-like
However, keyword
cumbersome.
as illustrated vector-element
The user
by the used
has to
example a procedure
definition facilities
in sum-positive-loop-macro), deals Lisp of six parts the macro Loop analogous Common as part
ACM
parsing
returns 6. of most
to the parts
discussed
in Section
(Recently,
standardization Lisp.
committee
of Common
it was too
1, January 1991.
Transactions
on Programmmg
Systems,
94
Richard C. Waters
they decided not to include the scanner-defining (of)) capabilities. )
complex,
vector-element
scan-vector
(path-name variable data-type prep-phrases Inclusive? allowed-prepositions data) (declare (ignore path-name data-type incluslve? allowed-prepositions data)) (let ((vector (gensym)) (1 (gensym)) (end (gensym))) (((vector) (,i 0) (,end) (variable)) ((setq ,vector ,(cadar prep-phrases)) (setq ,end (- (length ,vector) l))) (> ,i ,end) (,variable (aref ,vector ,i)) nll (,1 (+ ,i 1))))) difficulty that with with canbe the cannot the in the Loop body macro and isthat thereis that there by the these in a more are no restrictionson to prevent fragments. will
the
the body As a
no attempt looping
fragments [30],
presented with
provides
same
functional
simpler
Iteratorsin
for the mentscalled are processed including (Alphard one
CLtT. Among
iterators bythe
Algol-like
languages,
some
ofthe
most
use of looping
fragments
is provided forloops
bycLu
[28].
corresponding
to scanning
generators how
be supported summation
shows the
the vector
in CLU.
It also shows
the definition
scanner.
a coroutine = proc(V:
yields
scanned returns
one at a time.
ARRAY IINT])
end
end return
end SCAN_ I: END:
(SUM)
SUM_ POSITIVE_CLU VECTOR INT := = iter(V: ARRAY IINT]$LOW(V) IINT]) yields (INT)
ARRAY
together, macro
and
the
for
statement besides
the
sameas
things.
Nothing
scarmingis
ACM Transactions on Programming Lan~ages and S~stems,Vol 13, N0. l,,January 1991.
Automatic Transformation
supported. represent (In the example ed in non-local above,
95
ways
iterators
as corout form.
Loop
macros
scanner-defining
supporting this, in
multiple
iterators how
statement
collectors merely is no
While
of these
rather
doubt
supported
be straightforwardly
supported
in an Algol-like
language. The key difference the between the looping support and constructs looping and structure the ways. from how that means of the simply the only supporting one could they that the anysupport way the One is much that and can map iterative data collectors above are and highly nor the series correeffiidea
Summary.
expressions sponding cient, they to
while support
looping concept
constructs scanners
fragments
(potentially
unbounded) the
of a sequence This
of t resting constructs, The thing The fragments has more to functional lack other fact
fragments
preserves in several
feel
of the
however,
constructs clear
is not
transducers
fragments
procedures
learn
a new than
language
standard
composition.
of combination
on loop
about
above in
is the 2.
way By
they not
a variable, implicitly
transducers them.
fragments having
the constructs
the total
restrictions limits
embody can
are much
stronger
than
unnecessarily
be expressed.
8. BENEFITS There
start support requiring most are with, for the three series principal perspectives can from which at that to view they series can expressions. To in any language, includes along
expressions without
as embodying
complete
sequence language
expressions
a way
programming
removing syntax,
or causing
of the
provided ones.
by languages
as APL,
Seque
additional
fact
that
are
given they
of the of error
expressions
do not look.
encouraged
to think
of efficient
methods
results
ACM Transactions on Programming Languages and Systems,Vol. 13, No. 1, January 1991.
96
Richard C, Waters
particular, that
unlike
APL,
Lisp,
or
Seque,
are
never
tempted
to
think
expressions loops
are equally
A final pressions optimizable Given has the In shown into the series that
perspective
by the control
series By
ex-
using
potential
for being
as important of note
perspective,
it is possible
a result, loops
automatically This when also much instruct rays alyzing might because The less clear. would
in pre-exist
expressions. expressions
to obtain
the full
series
While sequential
been
explored, applied
optimizable Even of loops series schedule though for to opt imizable by the
series it series
of parallelism. pipelining for written the causes series situations in parallel not for most using
machines,
as the
machines
execution
of systolic process
If programs programs
a good
pipelined
computation relevant,
simplified.
2 appear context.
is is
in such
for mapping,
Neverthesuch
For example,
it easier
to vectorize
[4J programs.
ACKNOWLEDGMENTS The man, that the concept D. of optimizable Y. Tan, series and both research expressions A. Meyer, the concept at the has benefited C. Perdue, anonymous and the Artificial Support Naval and made from C. Rich, reviewers presentation. Intelligence was provided Research MCS-8117633, and in this the contained Laboratory by the the Computer paper of Defense National Techare those expressed the suggestions that of
a number significant This Advanced C-O643, Science and the nology of the
of people. Chapman,
In particular,
D. Wile, made
Y. Feldled to
P. Anagnostopoulos the
suggestions
In addition, done
suggestions
of Technology. Agency grants views not and (under NOO014-85-K-0124, Sperry, and
contracts and
NOOO14-75IRI-86166.14),
NOO014-88-K-0487),
MCS-7912179, conclusions
Siemens,
Microelectronics as representing
corporations. author
be interpreted
policies,
or implied,
organizations.
J.
The Design
and Analysis
of Computer
.41gorithms.
Reading,
on Programmmg
Languages
Systems,
Vol
13, No.
1, January
1991
Automatic Transformation
2. AIKEN, 1988). 3. 4. 5. 6. 7. ALLEN, mization ALLEN, A., AND NICOLAU, New York,
97
A.
1988,
Optimal
308317.
100P parallelization.
Design and
88 Conference ACM,
on Programming
Language
Implementation
J.
A catalogue
K
of optimizing
Prentice 9, 4 (Oct. Hall,
transformations.
New York. 1971.
AND KENNEDY,
Automatic
translation
1987),
of Fortran
491-542.
programs
ACAI
Tkans. Program.
BACKUS, J. Can programming be liberated from the Von Neuman style? A functional Cbmmun. ACM 21. 8 (Aug. 1978), 613641. and its algebra of programs. BARSTOW) Joint they 1984). D.
Automatic
F. New Rewriting York,
programming
IntelJigenre systems ACM 1984, 6373.
for streams.
(Aug. 1985).
In Proceedings
232237. that and reduce
on Artificial
BELLEGARDE,
In Proceedings
Functional
Programming
8.
BELLEGARDE,
F. Convergent
Workshop introduction M. Broy, effect P.,
term rewriting
transformation.
New York, 1985. of
In Proceedings
2441. 9. 10. 11 12. 13. 14. 15. BIRD) Discrete BISHOP, Softw. BLOSS, Symbolic BUDD, BURKE, Rep. T. G., R. J Eng. A., An Design. The
as Data of lists.
and
Calcuh 5-42.
NATO 389-402.
ASI
series, on loop
1986, IEEE
abstraction J.
programming
AND YOUNG,
1988), Loop
Code
evaluation.
Cornput. An APL
147-164. iteration macro. with types. Massachusetts ACM of Technology Program. Lang. 1987),
Springer-Verlag,
iteration data
103110. 16.
17. 18. 19. 20. 21. EMERY, 1979), software D. components. should 44, Nov. SIGSOFT 4, 4 (Oct. of Indiana for COmEnglesequences. systolic Ed.,
CONS Rep.
Department Rep.
Stream
processing. Aug.
Rutgers 1983.
Systems
AND GRISWOLD, . M
Programming
language
1988),
language
the Warp
In Functional L.,
Programming 1987,
Computer
G. Kahn,
AND WYATT,
Compilation
delayed
evaluation Languages
of Programming
AND STEARNS,R.
IFIP
requirements.
In Proceedings
IVERSON) K. 1985.
ACAI
Trans.
1979), 161176
New York,
Pascal
KAHN, G.,
1977 IFIP
AND MACQUEEN, D. Coroutines and networks Congress. Nortll-Holland, Amsterdam, 1977. Software SIGPLAN pipehning: 1988). ACM. An effective York, scheduling 1988, 88 Conference New on Programming
In Proceedings
machines. In
LAM,
hl.
Proceedings (Atlanta,
and Implementation
GA,
June
318-328.
1991.
ACM Transactions
on Programming
98
Richard C, Waters
28. 29
LISROV.
B.,
et. al
CZU
Reference
ilIan,~aJ,
Springer-Verlag.
New
York,
1981.
ORWANT,J. Support of obviously synchronizable series expressions in Pascal. Massachllsetts Instit,,te of Technology Rep. AI/WP-312i Sept. 1988. 30. PERDUE,C , AND WATERS,R. Generators and gatherers. In Common Lisp: the language.
2nd 31. 3z, Ed. C, Steele Jr., Ed., Digital Press, Burlington, MA, evaluation, and Its 1990, part
Usage.
9.56-959 1. .iCM
Prentice-Hall,
PINGALI, K.,
AND ARVIND Efficient demand-driven Lang and Syst 7, 2 (April 1985), 311333. poL~v~A, R., .AND PAKIN, S, APL, The -Language
Cliffs, NJ. 1975. N., PNUELI, A.,
Trana
Program.
Englewood
33.
PRYWES,
specification Program
program 1979),
generator 196217.
C., AND WATERS,R. The Programmers Apprentice. Addison-Wesley, Reading MA, 1!290. 35. RUTH, G , ALTER, S , AND MARTIN, W. A very h@ level lanwaw fOr business data Processing. 36. 37. 38 39. New York, G P. Massachusetts J JR W et. aI. 1986. Common Interlisp Lisp: The Language. Manual. program Digital Xerox Press, Maynard, MA, 1984. In ProceedArchitecture Reference languages, on Functional PARC, 1978. andhstoperators. and Computer Institlite Programming of Technology lt;ith Sets. Rep An LC!S/TR-254, Introduction 1981. To SETL Springer-Verlag, SCHWARTZ, STEELE, WADLER, ings .4CM
TFXTELMAN,
Applicative Conference
transformation,
Programmmg
Lang71ages
(Ott. 1981). WADLER, P compde-time. ACM, New P R R. R. R WADLER, ings WATERS, 1979), WATERS, Rep WATERS,
ACM, New Ycmk, 1981,2.5-32 Listlessn~ss R better than laziness; Lazy evaluation
In Proceedings York, 1984, 4552. is better than laziness loop loop II: Composing Springer-Verlag, programs. notation IEEE Listlessness cm Programs A method LetS. Oct. An ACM L$ymp. on Lisp and Functional
at
1984).
41 42. 43 44
In Proceed5, 3 (Mav
workshop 237-247.
as Data
Objects.
of Technology of
AIhl-680a,
1982. In Proceedings 1984). ACM, New of synchronizable Conference 110 In Proceedings ACM SIGPLAN .4CM Not. on the Principles
Programming 4.5. WATERS, SIGPL.4N 22, 7 (.July 46. lVATERS, ings 47. &3. 49. 50. 51 Computer WATERS, package. Press, WILE, 1983 WULF, Military ment R
interpretation
87 Symposium 7485.
and Interpretive
series expressions Languages part Rep. Language, 338-346. I: A Imers AIM-1082, 2nd Sciences
In Proceed1988). IEEE
tiomd
Conference
on Computer
Optimization
manual Dec
Massachusetts
WATERSR
D.
Series. In
MA, Generator
Ed.
G. Steele Rep.
Burlington,
expressions.
An introduction 2, -i (Dee.
to the construction
1976), 253265. 181.5A-1983,
and verdication
C7.S. Govern-
ANSI/MIL-STD-
Received
December
1987: revised
November
1989 and
May
1990;
accepted
July
1990
ACM
TransactIons
on Programming
Languages
and
Systems,
Vol.
13, N.
1, January
1991