Sie sind auf Seite 1von 99

A PLASMAPRIMER

, 8rian C.Smith
Carl Hewitt
, ..
ry Artificial Intel'ligence Laborat
ology Massachusetts Institute of .Tetn '
Marc,h 2, 1975
. DRAFT COPY ONtY
Copyright 1974 and 1975 by
8rian C. Smith and Carl Hewitt
AII rights reserved
.'
A PLASMA PRIMER
8rian C. Smith
Carl Hewitt
.. ry Artificial Intel'ligence Laborat
gy I echn Massachusetts Institute of
March 2, 1975
DRAFT COPYONLY
Copyright 1974 and 1975 by
Brian ,C. Smith andCarl Hewitt
I rightsreserved A
F'lIge .. 22:09 5 9 ! , 8 March PLASMA PRIMER ROUGH DRAFT
D.RAFT PREFACJn TO THE INCOMPLET
Hewitt 9 Copyrlght 1974, 1975 by Brian Smith and Car (
rights reserved A
ei1 t ich. hav.eri any issues w Thls version of the Primer Is' not complete -- .there are
discussed, and many that are mentioned need fur.ther clarificatioh. Appendik. A jists the th<1ngesthat
in the eated u which may help to te11 YOU what areas are likely to be c <1re current1y being worked
. near future
ighty. synt(iX .ahd to y f idify the previous y by writingthis Primer we are trying to so Obvious .
g]t .. own as PLANNtR: force an implementatlon of PLASM A [prevlous versions of which have. be k
tessed be bUilt. We feel that the development of crucial ideas ahd fUhdamental pri'tlcip4es haspto
ed .to be he lahguage has been desig . enough to solidify a language specification and. implementation
1 . tptob is a ma implementatio and convenient to use. We don't be.lieve that rnaking a powerfu
thl's ma:iiua1 of the basic actors is understood andagreed (jn. i since the exact beha v lor and protoco
has e d undetlyihg m ementation mahual. The lack of a cOhsistent and well-Uhderst and the Imp
k that emehtatioh attempts. But we don't thi led to a' certain amount of thrashing In previous imp
there is any excUse for this ahy longer. Certainly some areas as dlscussed in the Primer are sti11 fUtl
of PLASM.A tan mad'E!tb ered versi but the basic decisions have been made and a humanly engin
rUn this semester. We've spent ehough time talking and mak,ing throw<i.way implemehtatidhs. ft's time
! arge systems to make ah implementation whlch is useable for wrlting
Pagea
i 22:09 March 8, tg PLASMA PRIMER ROUGH DRAFT
TABLE OF CONTENTS
MPLETE DRAFT NC THE PREF ACE T
I INTRODUCTION
i The Language 1.1
:2 er Tj1e Ptit I.il
2 The Philosophy 1.lil
5 . AN INFORMAL INTRODUCTION TO PLASMA I1
5 to Message Passing Il1troductiot 11.1
5

Sending Simple Messages


e Messages Recelving Slmp
lI.i
11.I.b
9 S nple Definitiol Si lI.il
9 als ditiol COI II.ili
11 ding Bit lv I
11
1.2
13
Let
d Recursive Definitions s a Labe
Definitions
lI.iv
lI.iv.b
iv.c I
15 Matching Patterl 11.'1
.15
15
18
17
17
18
19
21
Page I
Introductlon to the Matchlng Process
s and Bind-to Equa
Data Structures
ing ication Matc App
se Any and E
ean Patterns Boo
Unpack
Reccurence of the sameelement in a pattetn
II.v.a
II.v.b
lI.v.t
II.v.d
11.'1.8
v.f I
lI.v.g
lI.v.h
Pjge il
22
2
22
22
24
24
24
25
2i
za
2!.
2'9
3'0.
30
31
31
33
34
34
3'5
.36
36
31
3
3
41
43
.4'1
Page tt
22:09 ) 19 8 March PLASMA PRIMER ROUGH DRAFT
The Operator match v.i .
Quotation Marks
Character Strlng Q.uote
e Q.uote Sing
vi.a .
vi.b .
vi .
DATA STRUCTURES AS AN EXAMPLE
Modular Distribution of Knowledge
nple Data Structure Operations Si
Sequences
"Pure" Lists
Queues
111.v.a
III.v.b
Speciflcations for Q.ueu.es
Abstract Operations on Q.ueues
ementation of Q.ueues Without Side-effe<:ts An Imp
Concrete Implementation of Queues 111.v.c.l
eues Q " ementation of "Pure ternative Imp An A
f Queuet Another Concrete Implementatlon III.v.d.l
s t of Expressio d Differentiatio a SimpJificatiol
III.v.c
v.d . I
"Pure
i
Collections
s ectlo Speciflcations for "Pure" Col 111.vii.a
ementation of "Pure" Collectiotls Imp III.vii.b
d Simple Side Effects Cells a
s Ce
Changing the Contents of a Ce
The In-a-cell Pattern
111.viii.a
III.viii.b
111.viii.c
npute" Llsts I "
es LOGO Turt
s Impure" Collectiot "
111
111.1
III.li
III.ill
I.lv
v . II
III.vi
I v .
I.vlil
III.I
III.x
xl .
PACKAGERS \I
PageliA
50
March 8,1975 22:09 RAFT PLASMA PRIMER ROUGH
LEVELS OF TRANSMISSION "1
91
12
93
nission Levels to Trans troductiol II V.i
smissions Apply Level Tra V.i.a
TURE ACTOR CONTROL STRU
V ,
13
4
5:5
6 ' 5
11
Continuations VI.i
icit Continuations Introduction to Imp VI.i.1I
Double-Headed Arrows VI.i.b
Recursiol ii . V
Iteratiol iii . V
18 Geherators VI.lv
.1
12
Same-fringe iv.a . V
Corotltines VI.v
6& ATION AND MATdHING ON APPLI EVALUAT , V
61
e1
INPUT-OUTPUT AND STREAMS VII
General Data StructureOperations VIII.i
11
11
69
Nex:t
First
Rest and Length
i.1!I . VII
VIII.i.b
i.c . V
11 PARALLELISM
11
12
Futures X
Parallel Sequences IX.i!
,'2,
Seriallzers IX.iii
15 Funnels IX.iv
15
Pagt1 iii
PLANS' X
Pagllv March 8,1975 22:09 PLASMA PRIMER ROUGH DRAFT
15
11
uatiol1 Control Structure Nested C0l1til
vocatiol Pattern Directed II
X.i
X.ii
18 RLD-DIREOTED INVOOATION WORLDS AND W
11 nes Fra XI.I
'1
META-EVALUATION
' 1 '
8
MORE SOPHISTICATED EXAMPLES
g Apply Level Message Access Examples USil
8
.
SP COND A L
Parallel And
1.
Total Quote
19 ofc:ons-c:ell t itio t A MetaCircular Defi
11 HISTORICAL PERSPECTIVE
82
.7
ALK , Relationship betweenPLASM A andSM ALL
d CONNIVER Relationship between PLASM A a
I.vi.a X
XIII.vi.b
i . X
ii . X
II.iii X
iv . XII
XI1I.\I
vi . X
90 ACKNOWLEDQEMENTS
A NS TI NS AND ADD RREC F' C ST L
Pageiv
X
XII
XIII
XIV
APPENDIX A
'11. t
22:09 19 8 Marc::h PLASMA PRIMER ROUGH DRAFT
UCTJON INTRO CHAPTERI
I.i --- The Language
' d fustemMode1ed bti Actors) [p'revidQs guage AI PLASMA (for PLANNER.like Lal
igned to offera iterature] is a computer lahguage system de ed PLANNER-73 in the versions ca
y activE! actors. An ac:;tpr is a potentja convenient formal syntax in which to write programs based
membet of . chunk of knowledge which communicates with other actors by sending polite rriessages
owed to treat any other member as an object, ,but rriust rather entei' into a a community of actors is a
ciety. Each actorthus retalhs 11. non-oppressive human s , dialogue with it, much as would happen i
. both independence a,nd dignity
d uring Machin-e!i in the same sense that the The actor model is a model of computatio
ig ine consists of"Wtiti the PDP-IO are models of computation. The primitive actlon for a Turing Mac
f a, PDP .. tOisthe a symbot on its tape, shifting rlght or left, ancl changing state. The prlmitive a:ctionf
n the actor mode,1 of computationis the ! execution of a single instruction. The primltive actio
se out cif the message.Just a,sa transmission of a message actor to another attor which can make se
sothere are PDP-IO requires sevel'al different kinds of p.rimitive instructions. in ordE!r to tun; $0 .a
y k.ind of. event that occu.rs 'in several different kinds of primitive actors. These are all based on the
the actor semantics: a message actor belng passed to a target actor. The act of message-passing is .Iike a
make conta(it, and thetl:\rget actor reachesout to receiv.e handshake -- the message actor reaches out t
. ong as the hands mesh sufficiently. information can pass betweehthem it. As
e 6f them .. M oint; PLASMA is justo Many languages could be grounded in the actor view
vey the .underIYin'g seh1anti'cs such it is transitory and superficial -- other languages may be found to cO
more conveniently. However any precise discu.ssioh Qf semantic issues. requites a language ot
tis ati expression. ' In the evolution of actor concepts at MIT this role has been served by various.gehe
. ects of these. evolv;ing ola and descendants of PLANNER. Unfortunately descriptions of the synta
.. ha ve been changing. confusihg, and sometimes not even consistent
guage w.hich i.s cteah .and a ize the syntax so far. and to formali.ze a It seems time to crystal .
$, setveas as expressive of good semantics. We very much hope that PLAsMA wI convenient. as wel
I e wi Y peop ementatiOl1, so that ma p ning i rU defined language for an I:\ctua e, we y stab moderate
. Use and crititlze the actor ideas
Page.
'agf! 2 March 8 . 1915 22:09 PLASMA PRIMER ROUGH DRAFT
lI'1" The Pri 1.11
iri PLASM A is not an easy language,nor Is it meaht to be.Itis easy t08.cquite a cert
immediate feel for message-passing in PLASMA, and to sense the flavot of PLAsMA, progtarns. B.ut
g -sbl\!i ex probi nce the langua.ge aims to provide an environrnen.t in which td. grow comp s
g 'ttionarrio er e .i , rnany aspects oft owsaccess to many ty,pes of .control sttuctur programs, it a
exity whi'Ch p a. co lted i f description of aprogram. This his res pieces' of code, and many levels .
pt aining the detalls of thelangtiage;is an attE! ly exp er, by carefu has put eff newcomers. This Pri
. ienation essen this a to
; need CiJfthat Ei er is not a reference manual, although Its index shou1dhe1p peop The Prl
Rather than listing and defining the structures of the language in a forrnal way, We have. instead .. tried
s, been 3,' c.ursi:ve y arise. Thegoal to introduce cOhcepts in the contexts in which they natura
introduction aimed. at a newcomer. Therefore we have attempted to inttoduce ndmechanism,wlth,out
)' .the otivatlon for its existence. Some examples, however, may seem fotced.sirtc providing some
at.tead{ng is inevitab1e consequence of the factt ot appeal to structures not yet presented; this is a can
f .the es make. t.I$e r eKamp grQw as futth y the m6tlvation wi linear but learning 1s not. Hopeftll ,
. particu1ar mechanisms being intl'oduced
', h towrite anguage, giving ehough ihfbrmati Chapter II is an inforrnal introduction to the
introdUcE!s e programs and to understand rnany of the papers on actor concept$. Cha.ptet simp
.- various data structures, providing sorne exarnples of real PLASMA ptograms. Chapters
explore various aspects of the language in de.tail. An hour wO.uld probably be better spend reading
. Chapter 11, rather than skirnming the whole Prirner
ssion:sof semafittc ve intodeep dfsc One thing that the Primer is not intended to do is to de
issues. This has been the role of the many papers on the actorviewpoint < ... >. At apprdpriate plates
. s of more theoretica1 aspects of actors and actor constrt.fcts refetence wil1 be made to dlscussio
I.iil --- Th.ePhilosophy
re.nt n some useless senseall programrning languages are equlva1eht. However vety diff
ofthe . perspectives can al'ise from approaching a problem in different 1ahguages. Your perteptid
y on the ftamework you bUild issues involved and your sense of possible solutlon,s often depend heavi
ost Thus a programming language Is in some s.ense an epistemology, But; pethaps more .. than
onment in which tdgrow other languages, PLASMA Is not so rnuch an episternology as an envi
, epistemologies. The unlfication of a!! prograrnming concepts under the actor concept. for ex:amp1e
Page2
Page3 March 8,1975 22:09 PLASMA PRIMER ROUGH DRAFT
eht in a given cOl1text c programming chunks as eq'tliva should not force a prog,ammer. to view all her
priate.to the tures and mecha.hisrns areappr d up whatever stru ow her to bui d tather a but shou
W,clata f y certain speclfic types of cOhtr d. Rathe,' thanforcing her to consider problem at ha
. exibl,e backgrdtind structure, etc., it should encourage her to superimpose anysuitable structure onta af
exity h'a:s g comp the hardware and software aspects of computer scienc.e il1creasi Both i
es .than we dld il1 the past; 50.f!it couraged us to bUi1d wlth more powerful, sophisticated modu e
ocks whichrestritt attempts to ease the pain of constructing complex systems have produced buildin'g b
guage in s.eatbh of a what one can do. And so many peopie. forced back toateas Ilkemachine
~ hcel1trat 1ow. them toc f1exibility. still have to pay the price of working at a level that is too low. to a
exibleand I f les that are sti l mod conceptual issues. PLASM A Is an attempt to provide high-leve .
. ation l Y sit efficient enough for, a
None of the PLASMA primitive or near-primitive actors ate too complicatedto .b:e
i ire somi:! effort o l req emented. Some of the most helpful constructs in the language, howevet, wil imp
ete1y trivia1. tojmplemel1t e. is not cornp the part of the implementor. The unpack operator. for examp
but is so often useful, making manipu1ation of sequences as easy to wri.te dowh. as to thi.nk "p . thattt.i5
1e ve to be implemented onte -- that is the wh y h on I wotth the imp1ementation effort. For it wil we
. es odu n gainof providing powerfu
anguages to devi:!lop new ideas .of lmake it easier than some other ly PLASM A wi Hopefu
anguage .for systems sUch as re. etc. LISP has served as an imp1ementation I struct ontro (;
ER. With the of PLAN MICRO-PLANNER and the first imp1ementatiori of an actor-based verslo
t .to ess tl:!taicitta. . opment of PLASM A we hope to provide a high-Ievel language that is deve
t isin this sense that' We hope that the pLASM'A . implementations of new data and contro! structures
. environment will be unrestrictlng
oun W111 be ar animate pro 3 To counteract historlcal habit, the female form of .the third person singu
. , . used in the Primer
Page S
P.lge 5 . Marth 8. 1978 22:09 PLASMA PRIMER ROUGH DRAFT
. '1'0. PL.A.SM4. CHAPTER I1 --- AN INFORMAL INTRODUOTIO
11.1 --- Introduction to Message
the actor semahtics 011 which PLASM A 18 basedis The basic(and only) event that occurs i
one in which a message actor is transmitted to a target actor. Thus the only t1'llhg thah. an actor.cah
eS's::tge ike 11. handshake -- the is send a message actor to a targetactor. The act of message-passing is
n!'; as .thehand.s tecelve it. As I actor reaches out to make contact, a.nd the target actorreaches out t
ity betWeeh thesetidtng There is a great dua y, information can pass between' the rnesh sufflcient
. ected in the 'PLASMA syntax ity is ref dreceiving of messages, and this dua a
Before dlscussing the mechanlsms for sending and receiving messages. we introouce Ot1e of
: the basic PLASM A data types, the sequence. The syntax of a sequence is
[ 01 1 82 ... 8
n
]
. Sequehces 1'tre discUssed turth.er in n' which means the ordered sequence of elements 81 through .
??? section
II.i.a Sending Simple Messages
,
. : is e syntax for sending a message actor M to a target actor Simp
(T <= M)
, y eqtliValent or, whlch is entire
(M => T).
Thus,
([this is a simple sentence]=> parser)
. led parser will send a sequence of 5 words to the actor ca
Fage 5
)
Page6 09 ! 22 1) 19 , 8 March PLASMA PRIMER ROUCn DRAFT
For eKample The symbols => and <= are read as forms of the verb "send".
ac:tor < .. [1 3]) would be read as an-actor is sent the sequence 1.3", or I'a sequence of I atid 3 .is sel1t .to a (
. 8h-actor
avors of "sends", and readers may have seen and been scatedaway here areactually many f
strUcture whic.hisrnore hese tend to deal with act()r contro . by arrows with mUltip1e heads and shafts
e $cheme ly asimp than usual recursive control structure, like that of ALGQL. There is actua genera
e heads and shafts which is qUlte friendly once it is explained. However the above sytltax is for multip
. . the simplest and much the most common
." s "<",,"or tliilJI> y write out either of the "send" symho Sometimes it is not convenient to exp1iclt
, Therefore
(A
l
A
2
... A
n
)
is an abbreviation for
(Al <= [A2'" A
n
])
y equivaleht to ete which as we remarked above is comp
) 1 A )= A
2
... An [(
T.hus
. )] 3 [ =< factoria (
] [ =< generate (
=< *(
)])] 2 +[ =< 1 ( 4 3 [
means
means
means
) 3 factorlal (
) erate ge (
2 + 1 ( 4 3 *(
~ ways tt)r Yj there a.te a icit Note that, when the <= or =) are written out exp
. expressions wlthin the parentheses
tains s 01' which co lclz.ed symba ession within parentheses which has no ita An exp
.. ed a transmitter y ca a transmitter arrow is usua
as. the LlS'P so note that arlthmetic can be expressed in infix notation [as wel A
semantics of sending "+11 ta a number. rather ducing the unusua prefix notation], pr
111 y, a.hd is explained than the other way around. This infix notation is used free
??? section
Page 6
Pige .,
22:09 1$ 19 , 8 March PLASMA PRIMER ROUGH DRAFT
The use of parentheses is similar to that of languages such as LI51', extept that by IJsihgthe
be more explicit about who is belng sent what message. However the meanihg i e ca arrows o
e form PLA5M A of any expression of' tl
(a-function arg I arg2 ... arg
n
)
y the list of p I correspond closely to its meaning in LISP. The LISP meaning would beto. a wi
ipnthesame t send . 8:-fu Irgl through arg
n
to the function a:'function. The PLASMA meaning is t
icatiori (see settid n a sequence wrapped in a message indicatlng that this is a ho!'mal app , ts argume
for more details). In other words it could also be written ???
(II-function <= [arg 1 arg2 ... arg
n
])
s the ows you to specify things otherthan sequences of arguments, ahdgiv The PLA5M A syntax a
. .!' exibility of writing the argumeht listfirst, where that 'is cleare f
II.i.b --- Receiving Simple Messages
he synbtx . Corresponding to the sending of messages is a: synta.x for their.receptioh
:" lscent of the LISP lambda expression, Is written as =>and read as "'R.ECEIVE remi
pattern body)
is a simple and common PLASMA expresslon whith creates an actor which is teady to tecelve rneuages.
For example the PLASM A expression:
Y + ] y .. >=(
15 analogous to the LISP
(Iambda (x y) (plus )( y
.. .r . ody) creates a fE1(:l;!i For the sake of exposition we will.call the actor that (=> pattf!rn
s it h The behavior of the receiver is. roughly as follows: when the receiver .1s sent a. message, It mat
against the pattern. If the match is unsuccessful, then the receivet rejects the .message. If the rhatch is
successful, the pattern returns an environment (\vhich may contaln bindings and ()ther effects. o.f the
matching process). The receiver then evaluates the body 1n this ehv1ronmeht. The, "1iI)" symbo1 1s
supposed to direct the eye of the reader along the normal floW of control through the pattern . intothe
Page
Page 8 22:09 !P March 8, t9 PLASMA PR.IMER. R.OUGH DR.AFT
body.
I messages are accepted through pattett)s or PLASM A Is a pattern-matching language, and a
temp1ates, which can be qulte complex. A pattern is an actor which detides whether it Wi11 match
et.tiGn y ih another actor ca11ed an ob ject -- the process is asymmetric. Patterns are dtscus.sed cohereht
W. One is e types of pattern matching are presel1ted n y in Chapter ??? Two simp an.d exhaustive ???
1 match. the objett3 to itself. The patterti 3. w g equa y thematch of an object against somethi simp
and the pattern [3 4] will match theob ject ma.tch the ob Ject [11 b c wi1 the pattern [8 b e ,
.]) 5 1 + 2) (9 w ([
ore interesting pattern is th.e binding actor, wrltten as a prefix ""7", which bint!s a messa.ge A
to al1 identifying actor. This pattern can be written as .. the-identlfier . Thus if 3 is rnat(;hed
t. If [1 2.4] is e be bound to g in the resulting environ agairist the pattern =X ,then )( wil
but if it is ] 4 1:2 [ mean the wholesequence then )( wi , matched agalnst the pattern
d be .bound to 2, a I be bound to ., b . wi1 then a wi , matched against the pattern [=a =b =c
4. Thus the LISP form e t
) body ... 2 )( 1 1lImbdll (x (
ent to the PLASM A form i5 equiva
) body ... 1 "x2 )("[ >!!!(
whatever message is sent to it and teturhs the . W.e can now write an actor which a.dds one t
: t resu
(;;;> =n (n + 1
Thus, the value of
1 + 5 ,,> (;;;> =n (n (
. 6 I be wi
2 ... . the xpr81;sio lonl rh e)(pre.s. 8 If the. receives statement has multiples expressions (i.e. (!!!> patt
ed .asthe y and the value of the last expression Will be retur ated sequenti.a be eval expres5ions wil
presumably be eva1ua'ted for their side ue of the recelver. The expressions other than the last wl1 va
. . e effects -- see section ??? for an examp
pa.ge .8
Pagl!! 9 22:09 March 8, t9 PLASMA PRIMER ROUGH DRAFT
-- Simple Definitions ii I
itioh, eveh thotigh Yje For the sake of exposition we need a mech.anlsm of recursive defi
owing syntax Cah be 1 e, the f section ??? Mea.nwhi won't be ready to expla.in how this works unti
: used
thename = the"'definition [
We can now glve our increment fUnction a name [note that it is changed to receive its atgument in
: j ) t e ictt send arrow (e.g. (Inete 1 work if used without an exp sequence, so that it wi
ent e inc:re [
e> [::n (
1 + n (
iii --- Cond.i ti()nals
. s ike to hav.e happenif a pattern match fai d So far we have no way to specify what we wou
ted bythe his ro1e is fl . mechanism in order to try a succession of alteri1atives We need a conditiona
: cl!Ises statement, which has the form
(cases clause 1 claulle2 ... clause
n
)
c:lllu.ol
tIIUiO.
f a I first sehd ,m to the actor c: If this expression is sent a messa.ge m, it wi
f . ue of the whole expression ue returned by c:lausel is the va accepts it, then the va
, ine. For example rejects it, then the message is passed to . clause2' etc . qown th
(1 ::>
(tases
(=> 0 yes)
(e> 1 no)
, Also O. I return Wi
Pige .9
'age 10 22:00 5 19 , 8 March PLASMA PItIMER ROUGH DRAFT
(3 =>
(cases
(=> 11)
(=> 6 -6)
(=> =x
(x ... 1
will return 4.
. f Will reject it e t If none of the clauses accepts the message, then the cases statemeht i
f general, when an actor rejects a message (for e.xample when it does not ma.tch the pattern), a message
' the form
): ized unreco II (
. led the complaint department which' somehow comes along W.iththe tnessage is sent to an actor ca
. y nate t fott efor programmers to Use, but u aint departments are very useful and are availab Comp
i Therefore We wi ? ? accessing them requires mechanisms that we won't introduce until Chapter
. ? ? . postpone a detailed discussion unti1 P
The expression
(rules object c:lauses)
is an abbreviation for
(objec:t =>
(c:ases c:lauses
: 49 evaluate to owing expression wi The fo
(rules 7
(=> 0 1)
(=> =x (x * x)
i . iar with the ften that the reader wi11 soon be fami use rules and cases so We wi1
e that the CONDexpres$idn does in much the ro es and tases statements fi y the ru Obvious
LISP. However, many conditions that in LISP are tested with explicit predicates ate tested .in
SP finds the L PLASM A with pattern matches. Consider the fo11owing two definitions: the one i
y ength of a. sequence (the two programs are rough isti the one in PLASM A finds the length of a
:) equiva1ent
. page 10
Page 11 Mai'ch 8. 1915 22:09 PlASMA PRIME.R ROUGH DRAFT
: P L
ength define (
) Iambdo(the-list (
c:ond (
) the-list nu
) 0
(1
) c:dr the"list ( us 1 (lengt p (
: PLASMA
Iength E [
coses (
][ > e (
) 0
rest-of-sequence != >=(
] ength rest-of-sequence + 1 (
arities between LISP and PLASMA, alid altholJ
i
gh it is oftf?h Atthough there are simi
that the ea ot nstructs in terms of LISP. this does ain PLASMA c convenient, as above, to exp
S utiQ ems grow more complex,appropt:ia'te s(;i lar. As programs and prob y stm guages ate essentia a
k more and more different in the two langu.ages; taking adva.htage .of thepecU1iarittes Cite liable to
es appear throughout the remainder become clearer as more complex examp of each system. This wil
. of the Prtmer
. II.iv :Q.nding
II.iv.a --- Let
There are two ways tn which simple identifiets can be bound to actors. One is t6 use the
the pattern part of a rec4live, statement Thts is used most often i binding pattern, as in
Another common way to bin,d identifiers is by using the let statement
Page 11
P.ge 12 March 8. 1975 22:09 PLASMA PRIMER ROUGH DRAFT
let (
] 1 ue name 1 liI va [{
] narne2 .. value2 [
[namen. .. vctlu8
n
]}
body) ,
. uatidn o{ b9dy uel ' namo:z, to value2 j etc., in the E!V'a means that nam81 will be bound to va
: The let statement above is equiva1ent to
>= ] u61 valu82 ... valu8
n
va [(
] ame 1 =name2 ... =name
n
[ )!!!(
body
s of a quadratic equatidn wl1engiven Fdr eX'ample the fo11owing attor returnsa sequence of the two roo
: the three coefficients
roots E! quadratic [
II .. b "'c =[,)=(
let (
]) p 1 '" (square-root, b * b) - (4 * 11 * c [{
] P2 '" (2 * a [
} ] P3'" (-1 * b [
) P3 + Pl) I P2 [
]]) P3 - PI ) I P2
Thus (quadratlc-roots 1 0 -1) eva1uates to (1 -1].
II,.iv.b ---La.bels a.nd Recursive Definitions
.- The bindings produced using .. are not recursive in either the let staterneht ot inthe
y evaluated inthe incomingenvitdntnent ete pattern, in the sense that the value tobe bound is comp
ment created by extehdihg the r aced in a new enviro ue and p and the identifier then bound to this va
incoming one. Thus
Pagel2
age t '
22:09 March 8, t9 PLASMAPRIMER ROUGHDRAFT
):;: 5 (
a> ["'x (
ler (
4 + x :; (x [{
) x
,.
. 9 I evaluate to wi
: n which allows tec.ursive bindings ogous to the 'et expressi There is a syntax ana
labels (
name I !! definition I [{
name2 e definition2 [
.}
bQdy)
This means that in the environment which is passed to body, orin other words the onein which
1.1 k .with ltiO be bound to the value of the corresponding defi h namek wil body is evaluated, ea
........ k fi.nitIQ y to the whole of d occurences of namek inside definitionk referring recursive
: ows as fo1 For example, We can evaluate 61 by deflning a recutsive factorial functio
labels (
factorial e [{
cas8s (
) 1 > e (
> e (
}]) 1 - factorial (n ( *
6 factorial (
g that Note the surprising fact that these are the only ways to bind identifiers,' meani
. global identlfiers d that there are n everything is scoped, a
II.iV.c --- Definitions
commotlactdr i We are now in a posltlon to examlne more carefully what is going
Page
. fixed points See < ... > for a more formal discussion of this subject in terms of behnviora **
Paget4
<,,'
March 8, 1975 22:09 PLASMA PRIM.E.R 'ROUGH DRAFT
are c:urrently t in the environment in Wh!ch yo y you would define factoril.ll definitions. NQrma
: wQrking by typing
3 factotial [
c:ases (
) 1 ] 0 [ ) 3 (
n ) 3 (
]) 1 .. n * (factorial (n (
In general, writing
[name = definition]
: y equiva1ent to is rough
labels (
}] name = definition [{
. -
... again reduce-eval-print loo all thlit read <: ... (
oWs ing. within prdgrams a1 llng Rhd for dynamic labe The parallel syntax for interactive labe
ber of mathemattca i exible Use of definitions. For example, suppose you have a file wlth a hu f
: definltions
] ... ;;: factorial [
) ... = ac:ci fibo [
] ... 13 cosine [
01' be the totlection easily wrap these up and glve them a name, by definingsome actot t you ca The
. : them
[math-definitions =
{[factorial = ... ]
[fibonnac:i e ... ]
[c:osine = ... ]}]
Now at any further time, execution of
(labels math-definitions body)
ttace of them will be itions hold, but ment in whlch the defl viro e evaluate body in a wil
, d outside the scope of the lubels statement. On the other hand, typing i fou
(enter math-definitions)
.. Page
Pagil!! is 22:09 5 19 , 8 Mar.ch PLASMA PRIMER ROUGH DRAFT
thi'3tefofi'3 ou ca . I the reader (i.e. "return") in an environment containing the definitiohs I (a wi
, . e's definitions, differeht Versiotis, etc., With gre:it ease ate and sWitch between different peop manipu
II.v --- Pa.ttern Ma.tch.i,ng
e anguage, and many differeht patterns are provided With t PLASM A is a pattern-matching
d s a the system's patter ists a ??? system. And, of Cdurse, new patterhs can ,be defined. Chapter
. hes dn his section introduces some of the,rnost com . strates the defihition of a pattern i
II.v.a --- Introduction to the Ma.tching Process
e ac:tbt,* the:! Patterh matchihg is, a 'hon-symmetric operation between two actors, !h, which o
eobjett ed, t rnatch another actor, cal patterh, is ah active template which decides whetheror, not it wi1
jts,sutha.s res te sorneusef s, an'd if it succeeds It, may prod A pattern match either succeeds or fai
. the binding of identifylng names to actors
Actors defined using the receives statements we have used receive all their messages through
, patterns. If a receives statement of the for
(s) pattern 'body)
' y if the mateh succeeds . match that message against the pattern 1, it wil ls seht ahY message at a
. ody be evaluated the wi1
, sidered the.pattern It is important to realize that if 8 and b are act()rs, then if a is (j
ythat if b is consldeted the patterl'i, thatitwitl y matches b ,that this does not imp and it successful
. earet as we discuss the behavior of specific pattettis become c This w rnatc:h 8.
II.v.b Equa.ls a.nd Bind-to
pattern, it,wi1t will,match. If 6 is used as ready seen that attors that are equa We have a
ein p th 6 ahd the value of (fl!lttorial 3).We have also used the 111 pattern (for eKa mat(h b
. to matc:h anything and bind it to an identifier )
Page 1&
Page 11 March 8, 1975 22:09 PLASMA PRIMER ROUGH DRAFT
II.v.c --- Data Structures
emetlts matth. In fact We haveseena y if their e erally match if and on Data structures ge
if the pattern I!I matthes .the ue of [x y z match the va wi examp1e of this. The pattern [11 b c
ts);ancl won't eme ues of the e ue of a sequence is a sequence of the va etc. (since the va value of
' match the value of [p q t s
ed a ar to a sequence but withoutany ordering of the e1ements fs ca A data structure simi
: written as
ilet 111 1'12 ... II (
or, which .is much more common.,:,,:,,:,
} 2 ... III
n
1I1 {
matc,h if any permutation of their e1ements match. For example ectiohs wi Co
{1 2 3}
match wi
{(4 - 2) =x 1}
. 2 e the pattern 3) witl match be bound to 3. For examp with the result that x Wi
I ernetits 111 a try its e wf ectio I match a sequence in the same way; sin,ce a co ection wi A co1
e orders to try to match, it doesn't mattet if the other data structure is ordered possib
11 match, there is tio way to ptedtct which w e sUccessfu If there is more than one possib
happen. For example
{=x =y}
matched with
{1 2}
apter m d y to 1.' C bind x to 2 a and y to 2, or wi either bind x to wil
can be written equlvalently as a2 ... an In fact sequehces, which we have been ihdicatlng as [a *':">:
) Jleqaence 81 1'12 ... I'I
n
(
Page .6
age' I '
22:09 ; , 8 March PLASMA PRIMER ROUGH DRAFT
f the present one discusses mechanisms for backing up to the match and tequesting another possibility
. is running into diffic:;u1ty
II.v.d --- Application Matching
It Is often useful to use an application as a pattern. For eKample, if
3)
se ythihg e t match a ess than 3. (Note that (2 < 3) wil I match any number is used as a pattern, it wi
whose value is true. ':<>:<>:'f,') Also the pattern
) e-as x r S8 (
Most binary predicates a.re x. match an actor y if and only if y is the very same actor a wi
.) defined to respond to tnatching if applied to one argument (considered to be the second
In fact any actor can be defined to respond to a "match-application" request; t,his is cliscus$ed
??? Chapter moredetail i I i
II.v.e---' Any and Else
viated as ",H ed anythihg and abbt There is a pattern which wl11 match anything, ca
, b jeCt rse, but ? does, not bind an fdentifiet to the I also match anything, of cot Wi The pattern
showing that you are not interested in what it actually is. For' example, the pa.ttern
3 [
ing ement sequence beginning with 3. For a pattern to match a,ny sequence begin wi11 match any two-e
. ow ack be with 3, see the discussion of un
auses end with a predicate T. In PLASMAit i8a1$0 In LISP most sequences of COND c
as ' suc which. is sUte to matc t tomrnon to end either a cases or rules expression with a patter
: owing abbreviatibn But ? . This has led to the fo
Page t
. y indicated by the actor y f,<.:,,:. An affirmative answer to a question is genera .;.
Page18 March 8. 1975 22:()9 PLASMA PRIMER ROUGH DRAFT
(else body)
is an abbreviation for
(=) ? body)
: ue ute-va ate an abso lowing trivial routine to calcu As an examples of the use of ellle consider the fo
!! absolute-value [
. a> (!:In (
rules n (
) 0 ) 2 (
n .. (
]) else n (
II.v.f --- Boolean Patterns
bjett ication of a 10gical predicate is asked to matth, it will try to matth. the If the app
atchtl1g. FO cceed whether the subunits s agail1st the subunits, and succeed depending
I match the pattern e. 3 wi examp
(1\ 5) (> 2
so the pattern and a
(v 5) (> 1 0
but will not match either the patter
(1\ 5) (> 3
nor the pattern
(v 3)
(> 19)
(1\ (> 10)
15)) .1
The pattern
Page 18
'age 19 22:09 I 19 8 I Mai' PLASMA PRiMER ROUGH DRAFT
) 3 1\ (

. 3 ess than urriber I bind )( to any I wi
50 one shd,uld not'tdepend e e to carry out their computation in para The predicates are 1iab
pleted., For y be co etessari the fact that either arm of an or wil or the order o,f eva 1uatio
rnber less than 6, .there wil1 match anything, but if the object is a n ) 6 e; the pattern (v examp
. be bound to it , O guarantee that )( wil ts
II.v.g Unpack
, res talled unp8ek inear data struct actor for manlpulating There i5 an exceedingly usefu
pattetns, ,ahd abbreviated as an exclamation point. Unpack can be used in any expression, hot just
patterns h<i$ted dn occurence i expresslons first. However its com genera troduce its use i i We wil
. to its introduction here
, writing out all the element5 t t e expression )( (written "!x" ) is,equiva Unpack of a
For example, If )( is bound to [3 4 5], then f x.
[1 !x 7]
to
[1 3 457]
Thus if Jt is bound to a essence the inverse of sequence brackets ,,[ ... )... Unpack is i
uate to the valuE! bf owing expressions eva sequencE!, then both of the fo

!X [
fUhctio LISP between Jistsj the LIS The unpack operator neatly cleans up the confusion i
d PLASMA LISP fists a CONS, APPEND, NCONC, etc. for example, using analogies betwee
: sequences, the following similarities hold
Pagei9
Page20 March8, 1975 22:09 PLASMA PRIMER ROUGH DRAFT
) ogous to (LIST X Y Z is ana
) NS X Y og'ous to (C Is ana
ogous to (APPEND X (LIST Y is ana
) ogous to (APPEND X Y ts ana
] x y z [
x !y [
] y
!x !y [
tghtly ification may not seem radical at one level, cohsider the fol.lowing s Although the simp
: more complex example. For the PLASMA expression
!e a [b !c d ![
: lowing og is the fo the L.ISP ana
APPEND (
A
CONS (
CONS (
B
))) 0 APPEND C (LIS (
)) E
ttean up with ication, which LISP confuses ahd has t The distinction between data structure andapp
) ... ( mearling a' linear data structure arid ... [ ear in PLASM A, with function, is made c the LIS
. meaning the transmission of a message
As a pattern, unpack does just what you want. For examplei if
[345]
is matched against the pattern
3 [
be boundto the sequence then )( wil
[4 5]
so the pattern A
y !:[
tag,e ar to =y, but has the adva I match any sequence, binding the whole sequence to y. It is simi wi
. of performing a check that the message is indeed a sequence

Page tl March. 8, !975 22:09 PLASMA PRIMER ROUGH DRAFT
The unpack operator sometimes has to perform non-trivial computatiOI1. For examp1e,
[!:x 3 !:y]
g a 3. If 3 is a terminalelement, one or both of )( ahd y may be match any sequence containi wi
wi1l , For examp!e if [1 2 3] is matched against the aboyepattern bound to the nu!! sequence
be bound to be bound to [1 2] and y wi
retctas If you don't need the name of the unpacked string, you can use the pattern
hus .... : egant abbreviation unpack anything". This warrants its own e "
,[3 ... ]
3 ith a match a.ny sequetice starting defined andcomp1ete PLASMA pattern, which wi is a wel
' y the pattern ar Simi
[ ... 4 ... 4 ... ]
. matc;h any sequence wlth at least two 4's !n It wi
It.v.h --- Reccurence 01 the sa.me element in pattern
. is a.mbigu().Us . ) x : A pattern containingtwo bindings to the same identifier (such as t:x ,
es it is convenient d. However, sometl ho since you don't know which of the two bindings of x wi
, y occurs more than ohce. Remihiscerit 01' t,l1e y if it attua ement on to bind one identifier to an e
bind within a pattetn wil occurences of the, exptession E binding of the labels statement, severa
e, the pattern to any actor that occurs that many tlmes within the pattern. Forexamp
] ... E ... E ... [
I bind x to tl1at e1ement ement that occurs tWice, and wi will match any sequence that has an e
tatc - The Ope:l:'a.tor I.v.i -
21.
Pitge 22 March 8,1975 22:09 PLASMA PRIMER ROUGH DRAFT
II.vi --- Qu.otati.on Mar.ks
; ks In the PLASMA system with diffeterit rneanlhgs There are three types of quotation ma
uation, and one is used to lridicate astring df eve1 of eva two of them protect an expression from one
. chatacters rather than an actor's name
II.vi.a --- Character String Qu.ote
. e quote marks are treated as a string of characters 3.h.d Any characters between a pajr of doub
e quote marks !iI set!fI by.the ot as the name of an actor. When an expresSion between .two ddub
reader. an actor is created which contalns and khoWS about .the sequence of characters. thusthe
expressioh
)" ote mark e q test of the doub t "this is pri (
sistiHg ot(a ge co t in this tase is sent a mess ri will print the string. of characters. Note th.at
e : y the actor which contains the charatter string sequence containing) only one actor -- name
. e quote
ll
y referred to as,"doub character string qUotation mark is norma
s Wh,ich h tnput-.output strea Character strings are of course used primarily in inter.actlons wi
. ??? , are discUssed in Chapter
1. , "
.':.',,';':.'
.,' ,
Single Quote II.vi.b
, :'. \
, e F'ot examp riatio Va pf eve be quoted to protect it from one A PLASM A expresslon ca
, lo if 111 is bound to 1, b is bound to 2, and c is bound to 3. then the expre
1 '; 'b c [
uate to I ev wi
[1 '; 'b 3]
whereas
Page 22
Pagf! 21 22:09 8 March PLASMA PRIMER ROUGH DRAFT
1 IJ b c [
ute to will eva
[1 I 2 3]
Unlike the LISP qUote, the stngle quotation mark does not quote the entirePLASMA
Thus eve y down one expresstonthat it surrounds down to any depth, but mere
'(+ I 2 (factorlal 3
uate to the expression eva wil
(+ I 2 6)
whereas
'(+ I 2 '(factorial 3
uate to the expression will eva.
(+ I 2 (factoril'll 3
Pa.ge 2s
24 e Pa March 8. i97/j 22=09 PLASMA PR.IMER ROUGH DRAFT
XAMPL n . D.ATA 8TRUCTUREB AS AN ... CHA.PTER
. stantly thtougho.ut the last cha.ptet Sequences are primitive in PLASM A, and were used cO
othet ces. Sev.erii d review the behaviot af. seque eral a ge I This chapter will discuss data structures i
I bUi1d up thetr lections, will also be presented. As we wi d co ists a types of data structure, such as
. rrnal introdUction t I illustl'ate some of the machinery introduced in the inf definitions we wi
I.i --- Modular Distribution of KnQw!edge I
li'tive:1y send and.receive messages, it. i8 re y an ob ject which ca Since an actor is simp
structure and the distihctiot1 betweeridataand unbiased with respectto asstlmptions about contro
ts ra.t operators. The neutrality on the issue of division of knowledge between data structure an.d op.
he in at1 actor system. f:J0w formatio distribute i the vat'ious ways in which one ca i can be see
one's purposesand the varidus uses to whichthe knaw1edge might choose to distribute it depends
y with differet:it.tlses of .th.e same can be put. Often it i5 deslrable to represent knowledge redundant
several diffe.rent places. The point is that the attorsatlow g In several gUise5 I knowledge appearil
. ow1edge in any way that is usefUI distribution of k
tions ~ pe . III.ii --- Simple Da.ta. .Struoture
Page 24
Pitge! March 8. 191" 22:09 PLASMA PRIMER ROUGH DRAFT
[first t ::
(!!I> [=a-data-structure]
(a-data-structure <:: first?]
[rest 1 =:
(e;) [::a"data-sttucture]
<= rlst1))]
thls others i t Chapter ??? explores these and similar actors in more depth. We WIII rU
. itions defi assume have para11e chapter such as add a.nd length which we .wil
se cornbihes a some se The only other function worth mentioning here is next, Which i
t sel1ds oUt the expected .,.xt . request for a first element and for the rest of a data struct.ure
a package (a pickage message, but expects the data structure to return the hext element wrapped up i
ssion) togethet wlth the - see Chapter ??? for a disc is an actor designed to carry other actors inside it
: odk like d requestwou response to a next rest of the data structure. A typica
(next: the-next-element
(rest: the-rest
Sequences I.iii I
, t5 umber of e1eme As we have seen many times, a sequente is an ordered list of an arbitrary
y represented as Sequences are primitive in PLASM A and are usu
] 81 a2 83 ... an [
tax ar to collectiohs and other structures, and meanihg that thesy ltten (to be simi so be w but can a
) y demands only one type of parentheses actua
(sequenc:e a 1 32 113 ... an)
t?, r.!;t 1y to f The sequences that come with the system, as It happens, respond meaningfu
iriteger i1 (itse1f .ln led with a ement, if ca so defined to return their nth e They are a and '8ngth?
. a sequence). Thus
) 4 8 b c: d 8 f [(
Page 2&
Page28 22:09 19 8
1
March PLASMA ,PRIMER ROUGH DRAFT
which 1s
)] 4 [ =< 1 b c: d e f [(
evaluates to d .
elemet1t of ,the The standard system sequences don't allow' you to' chahge what a give
ike rs that behavE! sequence is. However using the ce11s introduced "in section ??? it is easy to defiti,e act
' , vectors, so that, for example
) 4- x 01' (a-vector [n x -+ a-vector (
d mean that the nth element of the vector should be changed to )( . Such a definitionis given u wou
an example in sectio
I.i" --- PUre Lists
Since this is the first substantive actor definitidn in the Primer with side effects, we ilre goihg
re, $0 the ced bef d t mechanisms and types of behavior that haven1t been intr to meet severa1 differe
ow several minor digressions before comp1eting the definitioh have to fo reader is warned that we wil ,
. ists of
I e (; As mentioned abovei the contents actor sends ar'equest to First we define content9.
e ,t k ah,d t reac,h i ts C O way in which ,eonte I to send back its contents .. Thereis asking the ce
herefore we d,efit8e . osophy I the actor phi f. That would violate a by itse contents out of the cel
: ite tequest tont8nts to send out a po
[first =
(a>. [=a-list]
(a-list <= first?]
[1"89t =
(=) [=8-list]
(re9t? => 8-li9t))]
e, the a.ctofS p ike this. For exa As we will see, many actors in the system are buck-passers
t types of y send messages totheir arguments requesting differe simp first, print, 8val, match, etc. a
edge about differeht structuresj all the kn6wleclge behavior. This practice tends to modularize know
1.11 I witl contairi st actor. In our case the definition .of eO about lists is in the script of the I
Page 26
Page2 March 8. 1975 22:,09 PLASMA PRIMER ROUGH DRAFT
arge edge about how cells behave. Another advantage is that new structures can,beadded ,to a know
, t:E! U tri system without requirlng changes to any existing actors. Chapter ??? discusses thi,s issue of d,i,
, ' . competence ih more detail
, The lists we will deflne are reminiscent of LISP; that is. if I!I is an actor and b isa tist
eh1ent! ose remaining elemehts are thee d w b) is a list whose first e,lement is ii a s then C" (co
ts. In eme d rest of jts e a list wi11 be to ask for the first a operations of b. The most commo
. d (r8st C) wi11 be b other words, (fi!'!>t c) wi11 be I!I a
e Our first attempt to defi
l
] I!I .. b =[)!!!(
c::ases (
S) fi!'st (
) a
? S) rest (
]) b
. t eme if sent the message fi!'st? or !'est? will respdnd with the appropriate e S)( y Thus (co
its liody (previous Dlgl'ession ntlmber 2: Note that this definitlon has a cases statement i
definitions we have seen have only used cases statements for the whole definition). Thts mean$,that
t. At:tots ated cases sta;teme s-cell is called wlth a message. it returns to its caller an eval when tO
, mon inPLASMA ar) are co ts or receives statements (whlch are very simi which return cases stateme
. d what this means dersta and tt is ,essential to u
U,atidn of a .ret@ives edby the eva We havegiveh the name receive,r to what isretur
actor which is ready to receive, messages statement or a cases statement. A receiver is obviously a
is ready to Contents is a receiver whlch, when called with a message,returns another receiver whic
receive more messages. This is just what we want frbm cons-cell : we would like the vatueof
?' c:onl;-cell 3) to: be ready to accept such messages as 'contents (
ed td return receivers (by have cases or teceives I be defi this Primer wi Many more aC,tors i
r ity. See P.??? f other possibi their bodies) -- in fact it turns out that there is rea11y statements i
. more on thiS
' d meohe shou edge that it is indeed a list, in case s We might wish to add to a list the know
ask:
2 Page
Page 28 22:09 19 , 8 March PLASMA PRIMERROUGH DRAFT
=
con5
2 [
] b = )=(
cClses (
? e) first (
) a
? rest >=(
) b
? e> list (
]) yes
list. Using the LtsP itla as a tf?rminator and i II ist, which LISP calls We need a hu11
name:
ill e
cases (
) list? yes >=(
] e> nil? yes (
il? to JC. But d be defined to sel1d dut I.III? x) ) cou . predicate (i.e Presumably the nu
ent matched "i a more common test in PLASMA for the end of a Ilst would be to see if <111 ele
III.v --- Queues
III.v.a --- Specifications for Queues
ement queues asac.tors we need to examin exactly what behaviot we Before setting out to imp
be used to del10te a queuewlth wi "' are trying to implement An expression of the form (queV8 xl
elements )(1' ... , )(n' In this notation )(1 ,is at the front of the queue [and thus will be the first to ,be
. ts O eleme dequeued] and )(n is at the rear. For example (queue)denotes a queue with
Two very important properties of queues are expressed in the specifications given below. The
011 first property is that actors are queued at the rea,r of the queue.I:e. if enqueue Y ,is performed
: be expressed as ythis ca More abstract then the result is (queue )(1 ... )(n y ... 1 )( queue (
queue!g = (queue !g ( at-rear q
28 a:ge
,'age 29 March8. t97!) 22:09 PLASMA PRIMER ROUGH DRAFT
evaluates to (qu8ue 1 b e For example (nq c at-rear-o! (queue (1 b
the frontof the Another important property of queues is that, elements 'are dequeued fro
uates to eva e (dq (queue a b c queue. For examp
ext: (!irst: a) (rest: (queue b c "(
u in a so we need to express the fact that attemptlng to dequeue from the empty queue r,esu A
111 plaln":to: cd evaluates e (dq (queue) (else-co t, For examp aint departme aint to thecomp comp
: es owing ru the fo e:d < .. exhausted) The above property is expressed i (
) 'Pt t" i iiint-dept .. (exhausted => the,,:cQmpl dq(queue) (elilp,-cornplair'-to: the"comp (
."r.st-of rs,: the"fr9nt-of-g) (f'flSf: (queUe 1t : t-of-q !the-rest"of-q = ("ext dq (queue the-fro (
Queues ns III.v.b --- Abstract Operati
ly egate the responsibility fO,r attua Th,e opet'ators enqueue [nq) and dequeue[dq] de
quelie) ,sends the Thus (nq! at,..rear-o!the g operated to the queue bei performing the operatio
tor becaus:eit r ract op led anabs . The actor nq is ca e ) to the-queue to ask it to quet (lIq: messag
'of the keyl4e8$ e, proper t.se of ab,stract operators i tations of queues. 'fI 1eme works on all iml
this paper two of the m;tny posslble different for il1creasil1g tl,e Inodularity of systelns. I
. implementations of queues will be presented
[(nq =x at-rear-o! =the-queue) ;;
(the-queue <= (1Iq: x]
y we can define the abstract operator dq such that Similar
dq the-q (
) eXf-to: the-customer
(Jlse-complai1l-to: the-complaint-dept
sends (dq: (else-contplai,l-to: the-complaint-dept to the-q.
dq IIIthe-q (flext-to: =the-customer) (eIBo-cornplain-to: =the-c:omplaint-dept ([
=< the-c:ustomer (
=< the-q (
] nplai'l-to: the-complaint-dept dq: (elllo-co (
We can also define queue which is the abstract queue constructor expressibh ofthe
'. !
Page
22:09 5 19 , 8 March PLASMA PRIMER ROUGH DRAFT
01' nt where)(1 is at the fr I be used to construct a queue with elements )(1' ... , x wi ... 1 )( form (queue
crete itnplemelltatiolis given n is at the rear. The actor the-empty-qu8ue is defined in ca the queue and
. later in this paper
dthe.n ere are Ito elementB tl? be qufiu il r ;
the ernpty quefie retur' : .
elsebind. thequetuJti ;
'" e thtJ last queu.etJ ot the rect q ;
3 the qri.eue 01 the fir,t queue ;
queue e [
cClses (
) e (
) e-empty-queue t
111) [!=the-first-queuees =the-IClst-queuee (
! e-last"queuee at-rear-o nq t (
] queue !the-first-queuees (
III.v.c --- An Xmplementation of Queues
oved serted 'n the. tear and re A queue is a linear data structure suth that elements are i
from the front. We would now like to consider a simple concrete implementation. The idea of the
. etnentation is to define an actor c:ons-q such .that imp
queue !r .. (queu8!i!t ( at-!rorlt-o c:ons-q (
- .-
III.v.c,l --- Concrete Implementation of Qu"ues
: y-qu8ue First we define the behavior of the-emp
ueue a,A:ed ., you ore a t ;
el' ye politely I'tft ;
the-empty-queue e [
clses (
? e) queue (
) yes
? e) empty (
) yes
: q ) e (
) e-empty-queue t-o! t at-!ro cons-q (
t-dept to: =the-complaI e) (dq: (elso-complai (
])) exhausted =) the-complaint-dept (
the empty queue i.B fttdeed fJtnpty :
O ehqueutt if I'tllked :
fJ ottlY.elemeht s struct a queu.e wi'h x co ;
plai O dq a elemen' 0; cO ttllked i ;
, e tomplai,.t-dep 0 ' about being ethau"ted complai :
. ly defining the actor cc>ns-q y we proceed to actua Fina

'age 1. March 8, 1915 22:09 PLASMA PRIMER ROUGH DRAFT
!!! ) cons-q =x at-!rorlt-o! (is-a-queuo: =the-old-q ([
111 requlred to 6e a qU4JaAe x af thelronf 01 arl old queue whic to COrlstruct a queue wi ;
ses C: (
il asked toeltqueriey ;
lltmci a qfl.eue co ;
ti with x o,t ihe !roht .01 'he quer.te obtain ;
ear o!.th'e-oltl-q by queuihg :yat the ;
t'J !'rseelemette i! allked 10 dequeue ;
B the nextand thi1-old-q a. fff;t returtl X ;
? I!!) queue (
) yes
? 8) 8mpty (
) O
) e) (rtq: "'y (
q cons (
! t-o at-!ro )(
) q y at-rear-o! the-old-q
): 8) (dq (
] rlext: (first: x) (rost: the-old-q (
.s tation 01 Pu.r4':!l Q. ... eU III.v.d --- An Alternative Impleme
ementation of queues given il.bove has the property that although the dqoperatiotl is The imp
to the length of the queue. Now 8up.pdSe OW, being proportiona very qUick the nq operation is rather S
q operatioh is qUitkb.ut .the e to have queues in whichthe an application atises in which it is desirab
ust. scttisfy.the ementation y fast. Of course the new imp dq operation does hot ha ve to be particu1ar
entation is ba.sed on defihing an actClt It'OW'"CI ternative imple contract for queues. The a, origina
: lowing relation which satisfies the fo
(queue !r.) '"
Q'Ueues III.v.d.t ---Another Concrete Implementation
Again we need to define the behavior of the-empty-queu.:
Page 91
32 ge P 22:09 19 , 8 March
you fire a qttt'Jue if (Jsked i
wer yej politelY Qtl ; .
queue is irtdeedempt the empt ;
1& .. t'lsked ,oetiqiteue i ;
he onl1 elemf'Jtat grow Q queue with X Q3 ;
compI if allkedto dq an elemeitt ;
PLASMA PRIMER ROUGH DRAFT
1; the"empty-queuo [
c:ases (
queue1 ) .. (
) yes
? empty )=(
) yes
q: ::x ) i!! (
grow-q )( at-rear-o! the-empty-queue (
dq: (else-cor1tplaill-to: =the-complaint-dept ( )=(
]) aint-dept exhausted ,,) the-comp (
ustejl ,,, '''e complfJ4nt-'tlept g exh complaill abou' bei ;
. This in turn requires us to .define the actor grow-q.
grow-q "x at-rear-o! (i8-a-queue: "the-old-q) E! ([
queutt o be qui,.ed to corrstruct a queue with x at the reflr of an old queue which isr ;
o be ehe Mtorbelow th."q .s delined ; ---'-
O enqUfJue y if Qsked ;
the":q by quettitrty grow fZ queue!ro ;
ht ir#. ul i' Q8ked '0 dequeue
0 ' .' d send i ollk the-old-q '0 dequeue it8 next ;
ichwfll tllill ac;or w ;
e-old:"'q bind '''e first o ;
and ,het-est ;
t.u,.n t "(jh r ;
thefi,.tt4hd ;
8wqueUft ,. grow ;
with :t' at .. t1,e 'reat ;
Uft e olJ qu 01 e rellt o ;
eold-q "0$ "0 next eienift.nt 11 elllft ;
compiaina eitifJ re ;
en te'urn ''';
nti ' the:.(jleme,.t a' Jiril ;
, e"'empt:r.:.quette a t ;
Pa.ge '2
= the-q (
c8ses (
queue1 )=(
) yes
empty1 )=(
) O
) q: "y ) E! (
grow-q y a,-rear-of the-q (
): dq ( );;('
dq (
the-old-q
: ext-to
) S (
: ext
) e-old-q irst: "first-of-t {(
reBt: =rest-of-the-old-q (
: ext
) d-q o fir!lt: firstof-the (
: rest (
grQw-q (
{ x a,-rear-o
) rest-of-the-old-q
: else-complai,I-'o (
exhausted )=(
: next (
) first: x (
] rell': the-empty-queue (
Page March 8. 1975 22:09 PLASMA PRIMER ROU(;H DRAFT
s press.o III.vi --" Simplification and D.iffe:rentia.tion of
;! +[
cIses (
][ )!!!(
) 0
] 1=" =[ )!!!(
) F"
] F (+ !::G) !:H !:[ )!!!(
F' !G !H ! +(
] F' 0 !::G =![ )!!!(
. IF !G +(
] G (consti:lnt =0) !::H !:: F (constant ::C !:[ )!!!(
C + 0) !F !G !H ( +(
] F (* =C ;;E) !:G (* =0 ::E) !::H !::[ )!!!(
]) C + 0) * E) !F !G !H +(
!:! *[
cases (
) E (
) 1
] 1=" =[ ) E (
) F
] E) [!=F (* !=G) !::H (
F !G !H ! *(
] F 1 !=G !::[ )=(
F !G *(
] F (cohstant =C) !=G (c:onstant =0) !::H !::[ )=(
C * 0) !F !G !H ( *(
] F .EE=C !=G =E=D !:H !=[ )=(
]) E(C + 0) !F IG IH *(
"
= **[
cases (
] 0 ) 0 .. ([ )!!!(
) ,1
]) 0 .. ( 0 [ ) E (
) 0
1 [ ) E (
) 1
] 1 ) 2) [(1\ ( .. 0) .. F (
) F
F",G ::H .. [ )=(
]) F(* G H

Page !4 22:09 f) 19 8 March PLASMA PRIMER ROUGH DRAFT
) x =the-expret;sion ..
rules the-expresslon (
) constant ( >=(
) 0
X
) 1
) F !::G .. +( >=(
c)x F) (c)j< (+ !Q ( +(
) ... *( filter (
cases (
) stant ::C) !::G E!> (* (co (
x (* !Q C *(
) F !::G = *(
+(
) F (c)x (* !G *(
) c)x F) !Q ( *(
filter (
cases (
) F(constant ::n :: >=(
) x F ) n F(n - J *(
G =.
) x G e
G
*(
E!> (constant =C)"'Q (
) x G C
G
(Iog. C) ( *(
E!> "'F=G (
+(
) x F G F(G .. 1) ( *(
) x G ) F
G
' (Iog
e
F *(
)? ? filfer (Iog (
c8ses (
) 8) (Iog. ::F (
) x F 1 .. F *(
) stant .. C) ::F E!> (log(co (
] x F ) F-
1
(Iog
c
e *(
lections - Pur,e Co III.vii
IIt.vii.a --- Specifications for Pure Collections
} b by c) simp1ifies to {c extend {a b ( The expressio
(.xtend by =
Page 85 March 8. 1975 22:09 PLASMA PRIMER ROUGH DRAFT
)} ... ... { E .
} al !'i e y !midd itia 1'1: {!i e e l !fi midd ! initia !{
))} a' Ifinal i ) (r4ilst: {!i n8xt: (first: ( .. a fi ! ia i xt {!i
0' Pure Collections III.vii.b --- Implementatio
inear data structure such that the elements are considered to be Uhordeti':d ection is a A co
5 ection the-empty-co [
eeses (
) 5) (exte'ld-l,y: "'x (
ection ection X Ollro the-empty-co s-coI co (
ai"t-dept e-contplai,,-'o: ",the-comp ext? (e )!!!(
aint-dept austed =) the-comp ex (
) 5) (show: =the-tustomer (
e-customer t te (
ectio ifl-a: co (
: tJl has-elente (
]"}" d delintiled-by: .,{" a (
ettion}) e t 0.'110 {!=another-co e-eI4ilme t = s-collectio Co ([
5 ection e-coI t (
c:ases (
) d-l,y: =x 5) (exle (
ection ection X 01lto the-co s-co co (
)? e) (next (
: ext "(
) first: the-element (
) ection resl: rest-of-the-c:o (
) ord :b 1 =the"over .... ( >!!!(
, es b ru (
} ement !:rest-of-b !i!) {the-e (
ection rules another-to (
)} rd {!rest-of-b ver 5) ("'the (
) yes
) 1'10 e el. (
) 1'10 else (
) e) (sllou,: ",the-customer (
the-customer te (
) ection Is-a: co (
) has-a: first x (
) ection has-a: rest another-co (
])"}" imiters: 'f{" IInd has-de (
Page.35
Page SG 22:09 8.10 March PLASMA PRIMER ROUGH DRAFT
III.viii -- Cells and Simple Side Etfects
ives, and none of the actors .We have defined .so None of the PLASM A message-passing prlmi
avior. This freedom fromside far. involve any slde. effects, in the sense no actorhas time verying be
eU$er s t abl es the system to provide much more meanlngful.debugging assistance. ar1d e effects enab
ns. Sicleeffeetsshould be ean and free of surprising ihteracti f a computation c to .keep the history
' . icit when th.eit special behaviot is wahted avoided when they aren't necessary. and made exp
Il1.viii.a --- Cells
e prlmitive actor whlch embodies a side effect [;t be,havior PLASM A provides one and only o
some sense "keeps .a'notheratt6t Is an actor whii:h i A ce ed a ce ca that can change with ttme
arigeovetthe instdeit"j that i8 it knows of onJy one other actor at any given time, but that.actor can c
. tents Upoti request I also change its.co quish itscontents if asked. and wi I will reli course of time. A ce
the new be give s contents Wil has changed its contents. any actors w.ho ask for the ce After a ce
ace, After ace since before the change took p d access tci the ce contents. even if they have he
d contents were is lost.f, changes its contents, the Informatlon as to what the o
: ows s CJ.re created using the c:ons-c:ell actor as fo Ce
) contents I initi ons"c8
, e For examp
]) 123 I I " (c:ons-ce th.-ce [
. I cohtaining the number 123. You can ask a cel1 for its cohtents by evaluating return a ce Wi
contents the-ce (
for the asking for its contents. There is graphic abbreviatlo which sends a messa,ge to the ce
: operator c:ontents
cont8nts a"ce ( ent to is equiva a-c811 $
: 7 uates to owlng expression eva Thus the fo
ist of side effects that occUri or ce11s ly. of course. the system can be asked to keepa history 1) Actua
. . d contents could be defined to remember their o
Page $6
; ,
Pare a . March 8, 1971 22:09 PLASMA PRIMER ROUGH DRAFT
let (
]) 3 cons"ce ( =
}]) 4 y = (cons-ce [
Iy +
I.viii.b -.. Changing the Contents 0' a Cell I
: ts ts of a ce The synt<tx for changing the conte
(new-contents or new-contents)
Thus
' Ie (
}]) 4 cons-cell ( '" t {
3 + 4-
1 + I (
. 8 uates to eva
III.viii.c --- The In-a-cell Pattern
j; . The fbregdihg It is common to want to receive a message and p.utin immediately into a ce
tlal-corlte,.t n cohtainihg definitions of cons-cell did just thatj the-cell was defined to be a ce
e way to do thiS .. (which. is . a nitial-contents was never referred to again. The.re is a simp and
.)?? 1 tibn troduced in s pattern called after which ts i case 9f a powerfu abbreviation for a specia
: The following pattern
e na =@
ts IiI Note that g 1. I contaihi y-created ce d name to a new match any actor a and, bl wil
. f not to a itse bound to the ce
: I .. !3 for the moment) defini.tion of tO ( Uslng thls pattern we can write our f!na
Page S
Page SS 22:09 fJ Mafch 8, t9 PLASMA PRIMER ROUGH DRAFT
c:ons-ceIl4 e [
] within the-ce =@[
the-cell-Itself (
cas8s (
contents1
) in the-cell-wit $
) updarc: =new-contents (
) in :! new-contens wit the-ceJ (
] f I-itse the-ce
III.ix . --" Impure Lists
ffetno Our lists so far are pure, in that they cannot be modified, once cteated. As. such they
real advantage over the sequences provlded with the system. But we can easily extend the.mto.a1tow
d RPlACD,We. wl them to change their heads or 'tails. Rather than the.LISP names of RP[ACA :t
: tise the fo110wing syntax
... st he-list) or (!irst the-I -4 !i"!lt
and d be changed to istshou ement of the will indicate that the first e
) ist) or (rost the-lis.t ... y y -4 rest the (
. d be change .to y of the-list shou to indicate that the tai
We therefore need to have more complete d.efinitions of fll"st and .. est
) irst :::the-strutture ... :::new-first {([
] the-structure <= ({irst: hewfirst (
) re new-first -+ first =the-struct :::([
] the-structure <::: (!irst: new-first (
) rest :::the-structure ... =new"rest ([
] the-structure <= (rest: new-rest (

P.ge 19 March 8, 197.!;22:()9 PLASMA PRIMER ROUGH DRAFT
(=new-rest -+ 1'(18' =the-structure) $
(the":structure <= (1'081: new .. first]
y iate i requlres having a side-effect. which irnm ObVious1y changing an element of a cel
: s .. As a fitst try ist in ce ements of the need to keep the e indicates that We wil
[c:on93 E!
(E!> [@:::fir9t-cell @:::rest-c:ell]
(C8ses
(3) first?
Sfirst-cell)
(E!) rest?
$rest-cell)
(;;) list?
yes)
(E!) (first: =new-first
(first-cell 4- new-fi,.st
(=> (,.OSI: =new-rest)
(rest-cell 4- new-rest)]
wil ements. COhs This definition has a bug-- when asked to change either its flrst or remaining e
ves when they change their s return themse first or rest in, since ce I that it keeps its return the ce
ing for a listto give out to the rest of the world, .and by contents. This is not an appropriate t
. f when it is asked ro update itseJf d return itse ist shou convention the
., Mtrutt, but. It We can modify .the definition of c:ons-list to fix the bug using the label. e
. c:luMsy ahd r8ther obsc:ure
c:ons4 E! [
] 5) [@=first-cell @=rest-ce (
lal,els (
= the-list-itself [{
ci!lses (
? flrst )=(
) Sfirst-cell
? rest )=(
) 8rest"cell
? list )=(
) yes
) 3) (first: =newfirst (
) first-cell 4- new-first (
) the-llst-itself
) rest: =new-rest ( >=(
) r.est-cell 4- new-rest (
} ) the-list-its,lf
) the-list-itself
1?age 99
Page 40 22:09 I) 19 , 8 Match PLASMA PRIMER ROUGH DRAFT
ent.alid s does is to bind (recursively) th. name the-cell-itself to the valUe of the cases state at th W
ue of its body. whac:h is the then returns that receiver (since the value of the labels statment is the va
l1d f, which is the cases statement). Sincethe-c:ell-itself has its own namebo itse value of the-ce
. f up inside it, when asked to change contents it can carry out the requested ac:tioi1 and. then returnitse
oWilig 1 intuitive. so we Use the .f though this definition is correct. it is u However. a
:" abbreviation "
(name = body)
: t to which is equiva1el
(lal)els
{[!!!!!!! ;E body]}

ue of That is. the va
(name s expression)
yto rsive I refer tec wi ue of .xpressioh ,except that any use of name within expressio is the va
. the who1e of expression
.: of tonl Using ( ... s ... ) we can write a much clea,rer definitio
COhSs s [
] I first-cell @=rest-c:e =@[ )=(
= the-list-itself (
cases (
? first )!!(
) Sfirst-c:ell
? rest )!!(
) Srest-cell
? list
) yes
t: =new-first fir. (
) first-cell 4- new-first (
) the-Itst-itself
) rest: =new-rest ( )=(
) rest"cell 4- new-rest (
the-list-itself
g the distinguished ists by defini ly, we c!ln define a convenient syntax for constructing Fina
ist of them. It is thus simil<tr tn syhtactic symbol list, which takes a sequence of elements and returns a
: ce or seque Use to collec'io
Page 40
'age 41 Match 8, 19'15 22:09 PLASMA PRIMER ROUGH DRAFT
li/lt !=the-elements) s ([
rules the"'elements (
) S!) [] nll (
fi .. st !::rest ::[ )=(
. cons first (
])) Iist !r8st (
I!I.x --- LOGO Turtles
. Cells can conveniently be used to define actors which have state. Fof example, we Cf\11 ecisi1y
es be10w 1967, Papert 1971, Kay 1974]. Ih the e.xamp a et e [Dah define thebehavior of a LOGO turt
rams e pr ing Research Group for turt we make use of the special characters developed by the Lear
e to dtaw a causethe tutt ength wi owing program given a turtle and he fo . in SM ALL TALK
. ength and return to its initial state square with sides of the given
5 draw-square [
] =the-side-Iength !i!) [::the- (
le' {[the-sti!lrtlng-pen-position '" (pen"position the (
etut'tle ! ent pen pQsitiono e cl.t remembcr ;
Bflnd the tl.trtle the !olldwing ()ommt1nd,l ;
e pen t1bwn put t ;
jreceitJe 'he-turtle and the-iJide-len,t
(tell
z
length go !orwftr'dthe-sitle ;
rotate clockwi'Be 90
D
;
n o itB ongihal pd'i rektore the pen ;
: do 4 ,irn(!s (
) the-sido-Iength
) 90 W (
] the-starting-pen-position
I happen. An expression.of the actor that makes it a Below we give a definition of a hatch-
e the tUrt is ocatidn L.. If (Iocation: L creates a new turtle with initial form (hatch"
auses it to tbtate clotkWise =( !( causes the tuttle to go forward a distance D and =< !(
. through an angle A
Page 41
PalJe 42 22:09 March 8. i9 GH DRAFT PLASMA PRIMER RO
$ hl!ltth [
, t4fierst he foltowing ide () he 'ur,le maintains its state in cellll bound t )!!!(
the-location; the-heading, the-light, t'tndthe-pen-p6,ltioh ;
e otigit* ed ai by de!ault the turtle is ha'c ; 0 Iocation: @=the-Iocation (default: (Iocation ({
e de!ault headihg ls (}t ;t O : -hel!ding (default heading: @=th (
011 ;by default 'he llght 's 1Ight: @::the-light (default: off (
up ., ;the default peh po.itio pen: @::the-pen-pClsition (default: :!.} (
$ the (
0,.1) ,," 0 g commandli to the 'ur"e are seriatized '0 prevent timei ;
after receiving pOSllolIslo" o! ,be jenalt!l:er ;
serializer s (
: after-possession-to (
cases (
? heading )=(
) the-heading $
) W: ",the-angle ( )=(
... g the-headi (
360 ithe-headlng - the-angle) m,od
' ty degree g pluB the angle moJulo 'hree hUtldred ,f eadi the old ;
g di if asked for the curre' he ; ,
tr e con,ent,o! t,he-headi d back se ;
if asked '0 ro'ate clockwi.e ,through !'!h tihgle ;
g to be eafl4 e update ;
etidint d8 th jtlie distattce t()Wa
) the-tut'tle
? location )=(
) Sthe-Ioclltion
) the-distance = )=(
'" let ([the-new-Iocation (
+ ithe-Iocation (
the-distance * (co!line the"heading ([
}])]) e the"hellding the-distance * (si (
ce asked to go forward the-di.ta i ;
bft le. the neW Ibcdtio ;
"plas e old ldcat
es the-pen ru (
2. )=(
) draw-from Sthe-Ioclltion '0 the-new-Iocation (
'n dti :upda'e thelo the-Iocation ... the-new-Iocation) (
jBend baclt theupdated tu.rtl the
. ff o t i thelft tlllked i :i 9) light? (
;re'urn the conten's ofthe-llght Ithe-light)
. ) off light: (=setting whicll-ill (v turll ( )!!(
I! 6,. 0" . .,r eit " i a new he light ' if asked '0 'u ;
ight to the reque#ted .ettifCg e upda'e t ;
e updated.u.ti'te I"eturn ;
i.. llofiJh il t he pe ;
) g the-light ... setti (
the
if f'lilked '0 pl,tt the peri dOW ;
liepfJn ; updf,ltethe po,itioh #J ;
retur" ,he u.pd'ated tu.,.,'e ;
asked to putth(i pehd up ji
01 the pe update 'he posi,io ;
e'u .. 11 the updated tuHte ,.;
? pen-position )$(
) position the-pe $
2. ) s (
) the-pen ... ;!t (
the
:!. )=(
)! ... the-pen (
the
Page 42
Plge 41 22:09 19 8 March PLA.SMA PRIMER ROUGH DRAFT
etn eUi'rent ementation does not incorporate some of the mOfeadvanced features.of m The above imp
: ities g abi t the fo11owi eme eration turtles. The reader might consider how she would imp ge
. d to go forward avery great distance ly be to ta e might accide Panic Stop: a turt
. I it to stop We would Ilke to be able to interrupt it.and te
e time, they ons: If two turtles attempt to occupy the same position at the Sil is Go
. lided should both be interrLlpted and told that they have c.o
ight 081 ptovided that it ts s e to see another with i e ought to be ab Eyes: One turt
. O intervening tib jects pointed in approximately the right direction and there are
]. izers e in the appendix on the more advanced uses of seria Hint: see the examp [
III.xi --- Collectio!1$
to keep Lists and sequences are both ordered <;Iata structures. Sometimes it is usefu
, S i:!ttlt) collection of actors together without imposing any ordering on them. This section defines CQ
. ections of actors which are unordered co
ut Wi or !'.l;t1 The definition we will present is not designed to respond to fi!'st?
. In the real PLASMA system. however. fitst and I"est have tnote tespond correctly to next?
01- ,. t1 and if their arguments don'trecognited the flrs complex definitions than we have see
tyet rnessages they send a next? request and unpackage the ansWer if they get ol1e. We have n
t ... ete definitions of f s to deal with an actor not recegnizing a message, so comp introduced mechanis
8) , Wij But it is worth noting that (fi .. st s) and (t.c and rest are postponed Until Chapter
. ow ectionas defined be work in the PLASM A system if s is a co
ej th Collections do respond to requests to add. delete. and test for members. For examp
expression
(add an-element a-collection)
will insert an-element into the data structure, and
(delet. an-element a-collection)
will remove the element from the collection.
Page 4S
: passets add, delete and member? buck y we define the (usua Inltial
a g ~ 44 March 8. 1975 22:09 PLASMA PRIMER ROUCH DRAFT
add !i! [
] eIQment = .. -data-structure ~ a =[ )=(
=< a"data-sttucture (
]) add: an-element (
= delete [
an-element =a-data-structure =[ )=(
=< a-data-strutture (
]) delete: an-element (
= member [
an-element ::a-data-structure =[ )=(
=< a-data-struc:tute (
]) ntembe,.?: an-element (
. .
with t ists. a complete' de.finiti6 ding up a definition as we did for Rather than s1ow1y bui
of f t be glven in the sectlon below. It should be easy to understancl if the definiti many comments wi
. c:ons made sense
..
\.
Page 44
Page'45 22:09 5 19 8 March PLASMA PRIMER ROUGH DRAFT
== c:ollection [
e-cell ) ;1; (
. let (
}]) II Iength Sthe-c ( number .. (c:ons-ce [{
;
. on Is 11 comment g a seml-co owi e fo Anythlng on a
element9 Into ny Initia sequence of 50 far we have put ;
ny of them there are the-cell, and kept a count of how m ;
,)] 3 2 1 [ .. < n in number. Note that (collectlon 1, 2 3) i9 really (collec:tI , ;
] 3 2 1 [ contain9 90 that the-ce ;
,
the-collection"ltself (
tas89 (
) e) (add: =new-element (
')] the-cell 4- [!Sthe-cell new-member (
1 + number 4- (Snumber (
) ion-itself "collec th
ce whic:h ain a seque o con he-cell has been c:hanged
he the old seqvence with the new element ,added t is jU9
end. We update our count of how many elements al'e in the
. give this information out fast if asked c: c:ollec:t!on90 thatw
d ellsily y slnee W8 cou t neeessary rea Ac:tually this is
ength of th,. sequence which is the contents of get the
. the-cell
,
;
;
;
;
' If we wl!lhted to defihe gets that they would delete
he sllme actor, theh the add clause tiple cop!es of mu
: ike ook d instelld wou
) udd: =new-element ( )==(
rules Sthe-cell (
] ... e) [ ... hew"'element (
) the-collection-itself
else (
)] new-member the-cell 4- [!Sthe-c:e (
) 1 + number 4- (Snumber (
) f the-collection-itse
;
;
;

,
;
I rec:all egant use of ::.:J which as you wi e e te t N ;
abbreviation for !? (See Page O i ;
;
e) (delet(!: =lIn-element (
)) aint-dept else-complain-to: =the"comp (
, rule9 Ithe-ce (
.Page 45
'.ge 48
22109 5 19 , 8 March PLASMA PRIMER ROUGH DRAFT
] an-element !:y )=(
I 4- [!)( !y the-c:e (
1 - number 4- (Snumber (
) the-collection-itself
e el. (
= the-complaint-dept (
: ex/,uusfed (
Note the easy use of unpac:k to test for and remove an ;
ement out of the sequenc:e kept in the-cell. Also note e
)].[ . 01' l can be empty (I.e that either of
he message of e)(hausted which is sent bac:k to the
aint department using a funny kind 0' I!Irrow I1 dlscussed comp ;
. P ;
;
) 8) (member? =an-element (
es Sthe-cell ru (
] ement !=y an-e )=(
) yes ,
) else no (
; Similar to (delefe: ... ) in its search fo,,' the element.
) aint-dept the-comp = e) (n8)(t (
es $the-cell ru (
] y !::z = )(!::[ )=( ,
exf: y
rosf: (c:ollection !x !z (
else (
= t-dept ai the-comp (
) : exhuustod (
ement Notlce that the pattern wil' pic:k some unspetifiable e
out of the sequenc:e -- but sinc:ecollec:tions aren't ordered We don't
Posed care which one is c:hosen. We return it and 01 new collection cO
. f 0111 the other elements
;
]) number $ !!J) length (
; We have kept this updated so it is easy to give out.
;
ecttotis. "But it y way to implement co ar definitlon Is by no means the on This particu
. anguage ustrates some of the features of the PLASM A il
46
Page 4'1 22:09 5 19 , 8 March PLASMA PRIMER ROUGH DRAFT
PAOKAGERS CHAPTER IV
A message passed from one actor to another isjust another actor, like everything in the
ents.A cdmmon r ection of a liumber of compd system. This message actor is often a package or col
ts. The actor e, which packages up any number of sub-eleme message actor is the sequence, for examp
receiving this sequence often extracts the components by matching it against a sequence of binding
. . patterns
a sequence .or essage i ements of a ems with packlng e here are some restrictions a.nd prob
;lt similiar construct (such as the lists in LISP), that arise from the fact that the information as to W
his makes i.t . each element is is contained only in theor<;!ering of theelements !n the structure
yparts tract and know abou.to d.tfficult to make certain components optional, and to havereceivers e
m,?nerror,af i so, as any programmer knows, .it .Ieads tothe co of the col1ection of .elements. A
genera1 .. this.practicf:! r tihg in identifiers bound to the wrohg arguments. I ists, resu mis-matchlng
osophy that ating both .. the phi embeds important conceptual information ih representation, vio
d be conteht shdU iness) and thatconceptua d be hidden (for efficiency and clean representation shou
.) ity icit (for modularity and extensibi made exp
a For these reasons many of the common messages passed around in the PLAsM A system us
ements of a message, k.nown as a packager. Packagers ate differerlt constt'uct to wrap around e
ons are treated any differE!ntly ttdmany on, not because co normally given names ending with a co
y as a convention, to remlnd us of t.heir distinc:tive other alphabetic character by the reader, butsimp
. . type of matching behavior
emel1ts to be ehcasedj the he word "packager" is the name of the actor whichaccepts the e
ication of the elements to the packager is catled a pack:.age .. Thusj !n actor that is returned by the app
the expression
] rest: y ( = let (
) ...
. is bound to a package containing y rest: ... ) is a packa.ger, and (
case one or more actors ind e Packagers are actors whose primary interesting behavior is t
.. c e tifier of the t ge them when asked to match. The packager's name serves as an ide then divu
e semantic type of the encased actor. For examp
("lell-to: a-continuation)
functional applitatlons. An actor is the package used by the system to send continuations in norma
d bind this continuation to an identifier c by using the pattern cou
Page i
Page 48 22:09 1975 , 8 Marcl PLASMA PRIMER ROUGH DRAFT
) Io: =c the (
I e Wi By convention all but o ed with different numbers of arguments Packagers can be ca
d ement, a nguishede ed the dist on-package argument, It is cal e be .more packages. If there is o
ingpa.ckage if tht! match an inco package wil must be the f!rst. When asked to match, a patter
. ng package's atgumel1ts of the incom ectio package's arguments match a subco patter
: tch another package if 3 condltions are met m era1, a package wi1 ge
. t by the same packager 1: -- The packages were btli
the packages match, jf It ement i 2: -- The distingtlished e
, ess the pattern package has no arguments exists, un
ways successfu n which case the match is a !
3: -- Some permutation of the remaining arguments of the. pattern
ection of the remaining arguments I match some subco package wi
. of the incoming package
: e consider a hypothetical package For examp
match: an-object (
t: an-envlronment lnte lviro e (
: tch any of the following patterns This will successfu11y
) match: =the-object (
(match:)
: match (
I mllllt: =the-environment liro e (
: owing patterns It will n.ot, however, match any of the fo
(apply: =the"object)
match: =the-object (
) t: =the-environment e r ollviro (
the"new-environment : t liroJlmo eul-tln
Page 48
Pa,ge 49 22:09 19 ', 8 March PLASMA PRIMER ROUGH DRAFT
In each case stlb-packages are matched against their obvioUs cOtlnterparts if pos$ible.Ndte
that a pattern consisting of just the packager name with no arguments wtll rn:1tch a package that ha!
arguments.
The reason for ha ving all but the first argument in a package be packages themselves ,shou1d
les: ... ) to be a packager, and matched (examplel:' b t) against the f you defined (examl . be clear
: =x ,=Y =z) ,then x would definite1y be bound to 8 but yOU wduld not know pattern (example.
. which of Y or z wou1d be bound to b and which to e
Ordinary packagers can be defined using:;
:; the-packager-name [
]) mplete-example-package c packager il (
$ the sUb-packages thatthi where a-complete-example-package is a package written out uslng a
: p1ex numbets with packager is required to recognize. For example we could define a packager for co
:; : tplex co [
packager (
: cofltplex (
) 1 : al (!;-(
: imagi,lary (
his indicates that complex does not have a distinguished element (a questlon rnark. In that position
at most have the two sub-packages ihdicated. Of course both need would reserve that option), and wi
: 1owing expression is a complete package hot be used necessarilYi the fo
3.14 tplex: (rea co (
f for returns a definition which knows the name of the package inside itse Packager
??? Packager itsetf is defined in sectioh identification purposes.
occUr often in the Packages have appeared jn the defjnitions of data structures, ahd wi
workings of the intel'preter. Note that nothing th,at we have said about packages meahs that they .ate in
. any way an inefficient method of sending a collection of actors
Page 49
Page 50 March 8,1975 22:09 PLASMA PRiMER ROUGH DRAFT
CHA. PTER V LEVE.LS OFTRA. NS. MISSION
, "" ,
trol flo\Y. Fot es so far we have been vague about the nature of the co In our examp
example, in
(5 =>
(=> "'x (x + 1)
, which matches it. against.thepattern we have said that the message 5 gets sent to the receive.s statemen
u.s.t and then evaluates. the body In an environment' resulting from the match. But the pattetn is
ling .it what .itshould mat.ch andther actorj and the receiver must sent it some message or other te
ment Whetu d return the enviro against. Furthermore, the receiver must specify where the pattern shou
w whenthis f. And someh it is done. Then the body mtlst be sent a message telling it to evaluateitse
' the way ba.ck tlP to the litop" leve value is produced, it must find its way a
e tot.he user.A supervisor program happens in a magic way that is invisib y this a assica C
eged way. Andthere ments in a pr(vi uates tJr bindsarg with exa1ted stattlS reads defini.tlons and eva
s s answers batk toprogfa y funne e "return" mec:hanlsm, whichautomatica y an inaccessib is usua
.. who asked for them. Howev(!r, in the PLAsM A environment, nothing .is niagic and noth,ingis hi'dden ,
wltha:t1y ong as it was defined with. the power)to interact atany 1eve Anyactor has the right(as
I in message sent to it. There is no such thing as a "return" that is different fr.om aliY other actor ca
. et and so ignore its (;a way. If an actor wants to "r(!turn", it cando that, but It can a any substantia
send out arbitrary messages to arbitrary numbers of other actors. An actor's rights are invio1ate, by the
. system or anyone else
r .hand the ()th ' Thus no actor Is restricted in whom it must or must not send messages to.f.
catlhas everything that we have seen up to now has b(!en recursive in the sensc. that every fui1ctiona
way . a For a.n actor to behave in other than nor ted in a single return to the position of the ca resu
structure requires know abQut the deeper levels ofthe messages. that get paued o with regatd to cont
. . . around
untarlly restricted It8 rlght8 by signing a c()nt.ract that it will always Of course an actor might have vo >:<
. . y to a continuation, or some such e rep send a sing
Page 50
Pa.-e 5t 22:09 f) 19 , 8 March PLASMA PRIMER ROUGH DRAFT
V.i --- Introdu.otiQn to Trans.ml.ssion Le:vels
In the PLAS M A system the actual actors that get send from one actdrto another il.re more
the entire a'ctor that is sent eachactor (;a11 complicated than we have been aware of so far. We will cal
to iht1tide ope. Normal transmissions of the sort we have seen ate envelopes packaged u a enve
1. . , t communication, such as a tnessage v.arious pieces of informationnecessary to malntain cohere
. . continuation, etc
ransmissions we are referring metaphorica11y to the ideathat if. ydti s of access to By leve
't reach deeper into these transmitted actors then you can get your hands 011 more and rn,ore of .th
$0 access/ i5 the on.E! WE!. have see ed messilge-1eve of. access, whichis ca1 structure. The shallowest leve
far, and allows you access only to the messagE! portion. The simple send ahd teceive arrdw$w.eha:ve
l at.rdw5 fo It turns out. that thete are more powert , used access transmissions at this message leve
. reaching more deeply into thl:! strUcture of transmissions
is ca11Ect ,. In fact there are three levels of acces.s to transmissions: the shallowest tevel, leve
' 3, thedee'pest level. Leve lows deepff access, is calted the ordinary message level; level 2, which a
to. send garbage sed by the. syste 2 evel t and leve ow access to a parallel sed only to al level, is
evel 3. is not. restri'cteq co11ection messages, requests for definitions, debugglng assistance, etc.. Access to
eVe . this Ptimer. Messageleve1, or entioned furthet I not be but would tarely bE! needed, and it wi
oWsaccess to a:I 1eve at whlch we have accessed messages sofar.Level 2; the 1, is the leve
information affecting the Interpretation of parentheses and the control structure of, progra
f,.f,1 etc., are speclfied at thls leve . Continuatiolis, complaint-departments (see P
at which the eve The number of shafts on the send and receive .arrows reflects the
shafts meal1ing app1 ahd tW eve transmission is being accessed; one shaft meaning ordinarymessage
: level. Thus
is a message-level-send (or slmply a send), and -- >=
. d se is an apply-leve ._ >==
y ar Simi
is an (ordlnary)-message-level-receive. and a> --
. y-level-receive app is a ae> --
f s ed by the convent.io are gover eve 1 Conventions as to what Information is passed at what :":'
9. It,ls ized discout'se; thel'e is nothlng to prevent an actor from sending out a naked integer at l(:!ve civi
t.i y, but respond tneanihgfu1 unlikely that any of the actors provided with the PLASM A s.ystem wi
. are welcome to build your own system
Page &t
Page 52 Match 8, 1915 22:09 PLASMA PRIMER ROUGH DRAFT
V.1.a --- A pply Level Transmissions
eve1 message Accessing a tnessage at level I means that defaults are supplied for second
, structure In particular
(target <= a"'message)
is an I'abbreviatioh" for
"::< target (
apply: umessage (
) ted e'l-to: defau , (
) ellle-to: defaulted (
ylevet, a In other words, what looks at message leve111ke a simple tnessage 1s 1n (actj at app
tf): ... ) patkage} ahda so a continuation {in the (t"e,. package containing not only the message but a
, aint department {in the (else-'o: ... ) package}. The contlnuationis where normal IIretutns" go comp
ts such as a mts-match i al aint departmE':nt, as mentioned before, is where cotnp obviously, and the comp
. are sent
~ 'a:in evel you cah speclfy exp1icit cdmp transtnlsslons at this By accessing norma
f pes so you can specify patterl1S to mtitch othert departments, intet'rogate continuation$, etc. A
ing with matching and reduction, etc .. The detailed uses ofthese apply-level packages, such as those dea
t to tHttoduce ea r y t with in the next two chapters "- this chapter is tnere 1 de dea differeh.t actors wi
; s eve the idea of different
Page&2
22:09 5 19 , 8 Mlttch PLASMA PRIMER ROUGH DRAFT
TU;R CHAPTER VI . ACTOR CONTRO'L STRU
issimp1yan Our approach to the semantics Is centered on the concept of an actor. An acto
s actors.The ohly ements of a system can be vieWed e ob ject which can send or receive messages .. A
mesfto e is transmission of one actor to another actor. The ener$yfor cdmputationc a.ctivity possib
I be. referted to as I programs and systems wi low the script of an actor. A an a.ctiva.torwhich can fo
. . ism actors. The existence of more than one actlvator indicates para1le
VI.i -_. Continuations
tlirget1.t g as th is transmitted to another actor [servi ope Onte an actor, e, [serving as enve
I.Ise is to beof a the activator proceeds by following the script of t uslng information from'. For t
y I simp s.Wi e fo.r e to havesome structure. In many cas a.s a model of computation, it must be possib
so contain a continuatlon part .. Thenthe ehveldpe ma.y be will often a conta.in a message. I
represented as
. to: contlnuation y: message (the app (
, U$t puta.tion r co uatlon then all further instructions f f a message is sent without a conti
f' t dicate. ariother a.tt ined by the target. Sending a. continuatlon makes It possible. to i be deter
.) o'W ly be passed (i.e" an actor whose script the activiitor may fo which control can ev.entua
is ali's a semantic(or e to talk about continuations j The reason that It is useful to be ab
evaluator or a ike a something iclt that otherwise much of the control structure has to remaln imp
structure is a pattern of passing messages, in a computation. Ideally it shauld be mpiler .. Contl'o c
possible to dlstinguish between, say, recursive and iterative computatiohs as being two differ.ent patterns
. y characterlzed of message passlng behavior which can be precise
to a fUhction f can be implemented by passing to f an ehve10pe An ordinary functional ca ,
e d ue of.f s.hou with an expllclt continuation, Thecontinuation represents the actor to whith the va
O which structures can be expressed, such as jUtnps (i n addltion, other kinds of contro . sent
.] continuation is present) and co-routines [see Appendix
VI.i.a --- Introduction to Implicit Continuation.s
S Page
Pag! S4 22:09 19 8 March PLASMA PRIMER ROUGH DRAFT
y leve opes at the app enve From the previous chapter We knoW that continuations ate sent i
r havi access, cettain types of b of tral1smission. When you write programs using only message leve
uation of ar. during the eva n particU . are defaulted
),, 5 (
x (x + i " )!!(
inw'i,th that cam ,tio u tI ly: ... ) package containing 11. cO the ,message 5 is wrapped up in an (apI
the eValuatton request. When the receives statement receives this package. It unpacks the 5 messa.ge,out
dte ig unpacks the contlnuation. After matching the 5, agalnst the pattern =)( (we wi of it, and
k at, the expression above, that is ptetty rriuch ,the how just now), it evaluates the body. Now if you
nch of close parentheses: Therefdre we refer td, this end of it. There Is nothing mOI'e except 11. b
ns indicated icit actor transmissi situation as "falling off your parentheses". There are no further exp
. in the syntax
) 11 t fro t bui e owing: when a recetves state is the fol What happens !n this situat!o
_ t e packaged. which wewill ca y u fa11s off its parentheses, the continuation that the S) previous
n ot our n other words, if we wrote out a more detailed vetsi ,:>. gets sent the value of the body
: expression above, we would get roughly the following
)= 5 (
to: "c apply: "x (thfJ (
1 ... c <= (x (
y other. the transmission just like, a eVe ot qUite correct. Since this is a message However this is
value-of -the-body is wrapped in an (apply: ... ) package. Howeverthis time !!.2 continujitiohls'$ent m.
: t_. Thus a better description of what happens is _
)= 5 (
o: :C ly: "x (thfJ ap ( )!!!!(
) 1 + c <:" (apply: (x (
icit s off Its parentheses, the imp receives statement fa eve In other words, when the message
!. ot itself con.tai.n ue of the body in an (apply: ... ) package Which dQe.s continuation is sent the va
. continuation
VI.i.b --- Double-Headed Arrows
. uation of the evaluation request to the body y sends it a10ng asthe conti y, of course, It simp Actua *
Page M . ,
Page !i!i Marth 8.1975 22:09 PLASMA PRIMER ROUGH DRAFT
u can use s, y t to continuatio y, if you don't want this standard behaviour with respec Usua
evel message access. But it is sometimes convenient to be able to explicitly send message Without apply
g to reach ding anycontinuations, and to receive messages without binding them up. without havi se
. y level to the app dow
owing neW dlmension in send and receives artows.: a.doUble We therefore introduce the fo
a receive witl not bind one. For not send a continuatioh; a double head a send arrow wi head
example, the expression
(3 =) c:)
I send the message 3 to c with a continuation packaged up with it. However wi
(3 = c)
. I not bind up that implicit contlnuation wi
: owing threeate equiva1ent d be obvious that the fol t shou
1 + x = >!!!(
= : ply al ( >==(
t hera-to: =c (
) 1 + = c (
)(= : apply ( );;;;;(
en-to: =c l t (
1 + : c: <== (apply (
the differerit f1avoursof The reader may be happy to know that we have now introduced a
: 3rized below S fact they are sum I honor of t arrow that exist !n PLASM A, and
.send Arrows:
sends eve message -- = = =< >=
sends eve y -- app 1:::= == ==< >==
Receive Arrows:
evel receives message -- = )=
recelves eve y -- app == eE)
p.age 55
Pale 56 March 8. 1975 PLASMA PRIMER ROUGH DRAFT
VI.ii Recu.rsion
VI.lii --- Iteratio.n
. will. introduce e of some I,Ises for non-standard contlnuation beha.vior W examp As a usefu
which uses some of the mecha.nislTis of the 1ast section. In factthe an itera.tive deflnition of factoria
: structure lowing definition has iterative contro fo
. l e iterative-fac::torla [
) !!I (
>= ] 1 Q [(
oo
atio t =accumu cou =[ .
t rules COU (
) E! (
) ation u acc:u
elstJ (
=< O
) 1 + t COU ([
])]) t COU * accumulatio (
l iteratlve-factorla [
: E!E!) (apply (
to: =c the (
] 1 0 [(
oop a
ulatio accu t C()u =[ =(
t es COU l"u (
accumulatlo C ( > E! (
ellle (

) 1 + t COU ([
])]) t cou * ullltio accu (
Uat.iohs ti hever blnds an}' cO oo The reason that thls Is iteratlve and not recursive is that
e ly d therefote the o y continuat.ion it needs, a passed along with the tnessages it receives. The Oh
t sends jts ahswet to.that . that it holds onto, is the original one passed in with the original argument
oops. Ra.ther. each the stack of a.11 the record is kept y when it is done. Thus continuation direct
Page 56
Page 51 22:09 I; March 8,i9 PLASMA PRIMER ROUGH DRAFT
side effects, however, whith chahge loop's control strUcture drops off each time around. There are
the behavior of any actor. If the user wants, she can keep a complete history of a11 the events in her
. computation and be confident that no information has been lost
y reason for iteratlve"factorlal'j; accessing its ihtoming message at appty Note that the on
y out. toit d the ahswer direct level is to bind the continuation c so that insideloop it cou.ld se
ightly awkward and has Jed to the definltlon of a special actor ca11ed 8tart which hasthe This is s
.. behavior younorma11y want in an iterative loop but doesn't require apply-level message access
he actor start is defined on P. ???, and is very similar to the ( ... !! ... )expression. Like
: eral iin expressiori of the totm n ge . ;a ... ) it takes two arguments: a name and an expresslon ... (
) op-expression start the-Ioop-name the-I (
oop""n8me to g the owing properties: Rather than bindi returns an actor which has the fol
it bintls cl d wou oop-lillme = the-loop'"expressio d be what (the the-Ioop:-expression ,whlch wo.u
pa<:kage ... y ed with a stahdard (!!Pp oop-name to an actor which, whenevet it gets ca e t
... ) packa:ge n with another (apply s the-loop-expressI g a message and a contintlation, cal containi
y sehtto with the same message but wlth the contlnuation replaced by the cohtinuatioh that was origina
of value the that Thus oop-expression). name the oop (start the of value the
imi e"'Ioop-name the-Ioop-expression) is not quite the same actor as .the one that the-loop Ita .. t t (
t 1at tihUatiohs (j gtab a continuation the first timeand ignofe co gets bound to. Thls is how it ca
. rounds
: es rial. becd it.ion of itilrltivo-fa!lct earer by example. Using IItart our defi Thls will be c
iter8tive-factoriaI2 e [
>=(
] 1 0 [(
oop start (
t =accumulation cou =[ >=(
rules (:ount (
. .
) accumulation > e (
else (
.. oop
) 1 + count ([
])]) ac(:umulation * count (
) ... ue of the (stare Let's work through this definition. We wlll give the name s to the va
S binds Up the y iterative-factorial sends a sequence of 0 and I to s expression. ThllS initia .
1 0 [ call t . Theri s sends the message continuation tha.t comes in with [0 1] -- which we wil
binds the contint.iation o.f the 10op. The expressio the to the expressio n t c: . and the continuatio
ls off tts parentheses to n the expression fa y (since it uses a e> ), and if c:ount is equa implicit
5 Page
Page !j8 22:09 5 March8,19 PLASMA PRIMER ROUCH DRAFT
se clause is taken, then a call is rnade to loop and the value gets send to c as it should .. But if the e
P, when it receives this call, Jgndresthis O continuation. But ts and with some new argumel
continuation, and repackages the new arguments up with c . And then it sends this n.w package t
I the the expression of the loop again. Thus each time through th.e toop the contlnuation 'S c . A
. continuations that the expression keeps generating are ignored
Notice that the send arrow to (start ... ) in iterative-factorial2 ai1d the receives artow.I
d r the expression of the s'art expression, both have single heads, since they in fact ate sendihg a
. binding continuations
VI.lv --- Generators
ls bydefining We shall demonstrate how to define generators with and without using. ce
ed s.t.rea.ms generators that prodtlce the squares 1, 4, 9, 16, etc. in sequence on demand using a device ca
by Peter Landin [1965]. We wi11 develop two implementations that use the same interf<tte with .the
which requests the next element. The interface is defihed In sucha waythat polymorphic operator ne
" I as w!t I; Krutar, 1971; and Mitche11, 1971]. rtsWe 19 , ler I work with streams with side-effects [Ba it wi
akesthis happen wotks b n . functional streams [Landin, 1965]. The polymorphic operator hext which
essage n g the buck to the-supply using the imrnediately turnlng around ahd passlt
aln-to: the"compll!int-dept se-comp el<t: (e
aint-dept if it doesh'thave i ain to the'"(:().mp y for its next and to comp y <isk the'-supp to polite
next.
, t thesttea A stream-sequence consists of two components: a first which is the next element i
e a w we .defi ements after the first. :Be ds the rest of the e and a rest which is another stream that ho
uces t.he next larger square duces integers which are squares up to some .Iimit. It pr stream that pr
. ote squares t Iong with a stream for generating each time itis asked for it, and returns the square
. . .
PageM
Pige 59 22:09 19 8 March PLASMA PRIMER ROUGH DRAFT
, To construct a stream of squares
sequence of receive
a limlt of how many squares to produce
. t from which 10 begin produc:ing squares and a cOU
, Then return an <!ctor whlch
when 8sked either 10 produce the next element
, omplt!int-dept if 1I doesn't have on8 <: 10 or ,10 <:omplain
unt to see c::hecks the
the limit if it is greater tha
. and if so complains to the complaint-dept
Otherwise It
!> sequence which ha returns a slream
s next. element t IIs the square of the current. cou
and rest which is ;j stream of squares
with the same limit
. unt but whose count is one greatei' thlln the input c
Y f a ts the etemet1ts elementl;which pri Below we define a po1ymotphic opetator print
e stream whtch It is given. For examp
))) 1 : lmlt: 3) (count print-elemenls (cons-strellm-for-squllres (
". print "done print 1, 4, 9, and the wi .
. o. print-elements of a stream
. rec:eive a stream
. ts next Ask the stream for
, If it has a next
. receive the stream-sequence and bind it.s first IInd rest
. . Print the first of the stream"sequence
. ements of the test of th. stream"sequente Then print-e
, t e O If the ctreom has
." t "done pri
to. !orne that produces square integers U ow we define a port [a stream wlth side effects Be
f tWit.h 6ts g itse t produces the hext Jarger square each ttme It Is asked for its next, returhi . limit
". as the "rest behavior modlfied by a side effect
Page 59
Page 60 22:09 5 19 , 8 Marth PLASMA P}tIMER ROUGH DRAFT
, 10 c:onstruct a port for sqiJares
reteive a sequence of
any squCll"es to produce it of how i
. which to begln producing sqUares count fro nd
n c Let current-count be C! cell that Initially contains th& initia
. Label the actor whose behavior is defined below as the-port
, Return the-port which is an actor which
when asked either to produce the next
, 8 aint-dept if it doesn't have ain to a comp 01" to comp
count to se8 c:hecks the tontents of curre
, is greater than the Ilmit If i
. t-dept Cli d if so complains to the comp a
therwise it
. count increments the contents of the c:urr.n
Then returns a stream-sequence whic:h has
. t as it!> next elemEi
' 0 the sqUare
tents of current-count the cO
. d rest which is the-port a
so ext ta.na. ymorphic operator Note that we have defined the port in such a way that the po
be used to obtain squares from It. Thus Ih many cases the decisioh of whlch .of the. two
atel' recohsl.dered. Fot ementations of the square generator to use cah often bedeferred or eveh imp
e examp
(print-elements (consport-for-squares (Iimit: 3) (count:1 )
8r's s-$tream-for"j; d then print "done." However, the behavior of tO will also print 1, 4, 9, a
y the same as that of cons-port-for-squares. Once aport for sqQares has .beenprihtedth.en is hot exact
ity bui1t into behavior. There is ho "backup" capabi y used up" and has ho more usefu it is "tota
. Oh. the us.er of. th.epott ity if. it is desired is placed U ports. The burden of providing such a capabi
primitive can be painfu1 becarise Debugging a system where ports are used as t.he baslc communicatlo
fortunate etimes have tJ useful debugging actlvities such as printing the contents of a port sO
. effects side
t.of. being prihted a:nd In contrast, a stream for squares does not change its behaVior as a resu
15 can be used for other purposes at the same time such as searching for successive squares whose sum
y wlthout the use of tells as miost as efficient emented a ways be imp an odd prime. Generators can a
em; The lectioh prob s imposes more df a garbage co s except that avoiding the use of ce by uSlng ce
d s stems from the fact that .o e of prdgramming without ce the sty extra garbage collection
. y 'when they are no longer belng referenced generators disappear on
.. Page60
Page6i March 8. 197" 22:09 MER ROUGH DRAFT PLASMA PR
VI.iv.a Same"'frittge
tr._2) Which deterrfiihes fringe tr$e Consider now a somewhat harder. predicate (sarne
whether or not two trees treel and tree2 are derivations of the same sentencej i.e. whetheror hdttreei
s in the same order in.a left t() right tr!lversa1 of the fring-e cif and tree2 ha ve tht:! same termlnal symbo
d be easy if given a tree we had some way to construct a list of the eat'ly the problem wou the tree. C
... s of a. tree in the ord.er in which they occur symbo termina
r.el t works by making streams for the trees . Here is a first try at the actor sarne-fringe
111 etwo streams and tree2 that it receives as inputs and checking each correspondihg elerneht of t
. oW define be t makes use of an actor frlng. which We shal . turn to make sure that they are the same
he .liiime lring teBtll to fjee il two 'reefj hO/lJe ic de{ine s(lrne-{ringe w ;
ifJ(J trlJc
# two tree ;
0 ' two 'rees . 01 e lringes Bend t ;
ed companng-fr4hg e llJop na
which receive' twd liinge ;
* temen its lir;t 10 1 ge asks /ri ;
[t;8Me-fringe :;
(E!)
i .IJ ia am .
tll lirst elemeret alsoo,sk Iringe2 10,. ;
] tree 1 =tree2 ",[
)"' ]) fringe treel) (fringe tree2 ([(
start cOMparing-fringes (
] frlnge 1 =fringe2 =[ )=(
1 first ,fringe (
: flrst-to (
I )=(
first fringe2 (
: flrst-to (
J e t!JI he sa which must be ; , cases (
Xl >:;(
'" cornparlng-fringes (
) 1 rest fringe ([
]) rest frlnge2 (
) se no e (
: IIln-to comp (
! exhausted )=(
) 110
paring-l"nges.Wftll tare co re ;
, ntt1 therestbj ; ,
d ,he re't olfHngez a ;
" n gelem or,.e.lipofldi ges difler e fri
au'te.d e2 is e 1"tl ;
e 'ell , i{ fri'lge 1 rUfllI ih;o ,rQuble trying toproduce i,. lits ;
receive an e:t.haltBled complaint ;
au,'ed te.e 10 .liee illringe2 i.IJ e ;
(complain-to:
(s) exhausted!
(exhausted1 frlnge2]
eeds b r ae which of .the actor .rl Below we give a definition [due to Howie Shrobe
. y taneous incrementa11y traversing both trees in the required order simu
Page 61
Page 62 22:09 19 ; 8 March PLASMA PRIMER ROUGH DRAFT
iB t verllion b! IringfJ that behdves tl8!ol'o equivale ge is a ri !;
i'epeive ;
actbt' d return fl a tree a ;
flX' and then retutt111 which waits '0 be asked lor the ;
01 , inte,.ttal-/rinte ;
the t'ee qnd ;
; r i'sn,ex actor which when it is alllted a ;
se"d. btlclt e:t'hausted ;
fringe e [
) e (
the-tree =[
)? e) (next (
fringe interna (
the-tree
) aint-dept the-comp : e> (next (
]) aint-dept exhausted! .. > the-comp (
t,an,il al nodes !,.om i'it lirst argltme ge delivers up termi al-fri inter ;
, eti ttrils '0, 'tB lieconddrl(tl. ' d t"e it iB eXhal.tlited a ;
p'plier ode an,d tin altel'hdtes receive a ; ,
hllos 1(,1" thqj ,hode, ar ;
" lal t'heh re'u,f il it is ter,mi :
inext iB i'h,e tiotle
, ahd rest the alte,.nate, Bupplier ;
infil,returh t ter ellle i' the node is ;
/rihtjjol te,.tial the i :
n(jde ub #, e lef t ;
, ch I1 allked 10" itil n,e:tt ,.,' ... rn ate 8upplier wh a'ld atl al'er ;
' 01 nte the ih,c,.ltal ;
ght .ub-hodo antJ the :
e alte,tlflte 'uppllet>
[Internal"fringe e
ier ternate-!lupp e-i:l the-node =t =[ )!!!(
es the-node ru (
!I!) (termlha (
next: the-node (
iCilr ternate-!lupp rest: the-i:l (
se e ( ,
fringe interna (
) e-node eft t
e> (ne)(t (
internal"fringe (
) right the-node (
]))) r i ternate-supp the-a ,
VI.v -_. Co"routines
Co-routines are a control structure which are often used by program,mers ih artiticiat
; I 19 , ihtel'igence and systems programmihg. They have recently foUhd ihtteasing popUlarity [Hewitt
] 1973 , Bobrow-Wegbreit, 1972; McDermott and Sussman, 1972; Davies, 1972; Hewitt, Bishop, and Steiger
y e. Eat g stY i edge-based applic<ttions as the foundation for a dialogue-based progra know i
ligence programs were mainly organized as multi-pass heuristic programs consistihg of' a. Artificial Inte
! lt i pass of information gathering, a pass of constraint analysis, and a pass of hypothesis fOfmatio
e ,because,it, il dfte flexib y recognized that multi-pass organizations of this kin,d are i now genet'a
I stages a dialog'ue at a s i necessary for information to flow across these bouhdari,es in both direttio
. of the processing
ahd syntactic passesof Co-routines were used by Conway [1963] toconvert the sepa.rate lexica
strUcture[i tro a two-pass compiler into a single pass compiler. Using cel1s and gotos, a (o-routine (o
t to do this ih the following way. We can be bui anguage like PAL, GEDANKEN, or CONNIVER a ,
yzer of yzer and the syhtactic ana exical ana assume that there are four cells known globally to both the
. ' " : the compiler
62 Page
'age 61 March 8, 1915 22:09 PLASMA PRIMER ROUGH DRAFT
analyzer exica essageto-lexical: cel! for messages to
yzer for messages to syntactic ana i!lgeto-!>yntactic: ce es
yzer for r,esume-polnts of lexical ana resumelexical: ce
for resume-polnts of syntactlc analyzer resumesyntactic: ce
: owing To start the system execute the 'fo
of resumesyntactic with startlng-syntactic"resume"point Update the conten
Call the procedure start-Iexlcal-analysis with the-Input-character-stream IIS, its 8rgUment
exica1 item L , yzer has found the nE!xt ana exica Wheneverthe a-Iexlcal-procedure of the
: ow yzer by executing the code in the box be then it can resume the syntax ana
Define a-Iexical-procedure to be
(1 argument-to-a-Iexical-procedure
' ,
I!lt i!!!!!!!!!!I!!lt!
e contents 01 resumelexical to be a-Iexical-resume-point Update t
. which is defined below
o be L hen update the contents of messageto-syntactlc
' ts of resumesyntactic te and then goto the cO
: lexlcal-resume-polnt
' Read the contents of messageto-Iexlcal
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I !!!!!!! I!I!
). valuelexical as the value ofa-lexici;'Il-procedure R.tur
.. analyzer, a-Iexical-procedure is.an ordlnary procedure; it iscat1ed ' exica Note that within.the
.. he 1exitat ana1ytet . and returns with an ordinary procedure returh aryprocedure ca with an ordit
. ; need ha ve no knowledge th,at a-Iexical-procedure interacts with the syntax ana1yzer
e the ocedure of the syntactlc analyzer needs more itiptit it can resu Whenever a-syntax-p
: ow 1exical analyzer by executingthe c.ode in the box be
. Page
64 March 8. 1971 22:09 PLASMA PRIMER ROUGH DRAFT
o be Definea-syhtilx-procedure
1' argument-to-I'I-syntl'lx-procedure (
1 !! !!!!!!!!II !!I!!t !!! !!!!!!!!! ! ! !!!!!! !! Z!!!!!!ZZ!!
I
I
t Update the cont,ents 01 messageto-Iexic:al to be 'next
I ents o. resumelexic:al' d then goto the <:o a
I syntactic:-resume-poiht: ..
' 1 , . ' ts of messageto-syntactic: Read the c:onte
z !!% !:!.!::!! :t !.!!!:!!:!!!.!!!.:! !!:!. !!.!!. !:!!!! !!.! !!:!!.!!!.!!!! !:!:!!:r! :t!.!.!!!! !o
Update the contents 01 resumesyntactic to be a-syntactit-resuMe"point
. ed below which is defi
). tax-protedure tactic as the valu8 of a-sY Return valuesY
vecl in Using explicit envelopes we shall indicatE! how to eliminate the side ,effe<:ts inv
t sth'eme cy. O oss of efficie co-routining between the syntactic and lexical analyzers wlthout sevete
y which we assUme that we have the abitity to, explittt CtlILIS i to l-ca can be viewed asan extensio
e to bind the messagein a oped that is sent as oppos'ed to only being ab plete enve bind the cO
the messages passed increase the sile of a that the l-calculus allows.We wi envelope which is a
d tie a t ude what would have been .th.e cdntents of resuml!JtY analyzer to inc around inside the lexica
u.de what would have bee,n th,e c er to i increase the size of the messages passed in the syntax analy
of actor ,semantics ahd PLAS M A has been designed for the d.irect realizatit:l contents of resumelexica
tage of ows expliclt access to ehvelopes when this is desirable. Theadvil, so has a, syntax which a
straightforward icitly .bind the whole envelope is that it ptovides a powerfu being. able to exp
hesema.l1tits of . e rigorous semantics defined ih terms of actors co-routine mechanism with simp
seem td be inextricably bound up with alternative co-routihe mechanisms [such as Landin's j-operator
.] 1912 ds emented [Reyno they are' imp the detailed evaluation' mechanisms of the language in whic
owlng Using evelopes to implement' coroutines, the system is started by executihg the fdt
: I procedure ca
) ysls put-character-stream begin-syntactic-ana analysis i exica start (
item L. then it yzer has found the next lexica pl'ocedure of the lexical ana Whenever 'a-lexica
: ow yzer by executing the code in the box be can fesume the syntax ana
Page 64
Page 65 22:09 9 8 Match PLASMA PRIMER ROUGH DRAFT
Dafina a .. laxical-procedure to be
Receive-envelope (apply: [arg;ument-to-Iexical-proc:edure resumesyntac:tic]
(then-to: reply-to-Iexical))
%-!: Z tt I !!.
resumesyntactic is sent the envelope
(apply: L
(then-to:
rec:eive-envelope {apply: messageto-lexic:1I1
(then-to: another-resumesyntaetie))
))] othe"",resumesyhtattie: reply-to-Iexical is sent the message [valuelexical a
!!!!!!!!!!!!!!!II !!!!!!!!!!! !!!!!!!!!!Z!!!!!!!!!!!!!!!!!!!!!Z !ZZZ!Z!!Z Z
yzer needs more input ftom the lexlc:a Whenever a-syntax-procedure of the syntax ana
: ow yzer by executing the code in the box he analyzer it can resume the syntaxana
Deflne a"syntax-procedure to be
tax-procedure resumelexica Receive-envelope (apply: [argument-to-sy
then-to: reply-to-syntac:tic (
'tti z!:! :!:!.Z!:X :t !!!!!! !,!
I
I
I
I
I
I
I
8 resumelexical is sent the envelo
ply: 'next a (
; then-to (
. receive-envelope (apply: messageto-syntactic
)) then-to: another-resumelexical (
))] ical t the message [valuesyntactlc anothel'-resume'e reply-to-syntactic is se
Z !tt '!!.! Z !! !!.!! !!!! !!!!!!! :!!.!.!:!:!!::!.
the above application becomes mote jtlstifiable in cases where a. Use of co-routines fo
re yzer is needed. This happens whet1 m yzer and the syntax ana ana exica gue between the dial
yzer. Ai1 ana interesting messages than simply 'next need to be sent to the lexical analyierby the synta
ication which needs this klnd of sophistication is an error correcting compiler whete both 1exica app
. ahd syntactic errotsoccur in programs being compiled
Page 8&
86 Page 22:09 March 8, 197 PLASMA PRIMER .ROUCH DRAFT
Q AND MAtCHt CHAPTER VII ... EVALUATION APPLICATIO
" f 1 had more time, 1 would write you more briefly
Clcero ---
This section was wrltten once, was then discarded, and a tnore conipact version is in progress;
Page66
Page 8'" March 8. 1975 22:09 PLASMA PRIMER ROUGH DRAFT
T ANP STREA1\IS CHAPTER VIII . INPUT-OUTP
VIII.i --- General Data Structtire
. f data structurE!srespond to a.ss c era First we examine the sorts of messages that the. ge
y useful to extract elements from; by conventtonj if I is a data structure Data structures are prim<iti
: be deflned genera I i s wi owing fotlt functio thenthe fo
(first s)
(rest .11)
) s ne (
(Iength s)
errierlt if tht! data structure, ot sirnply some e ement of F"irst s) is jntended to return the "flrst" e (
el1t; anc1 Md e I of the data structure except this e ot ordered; I'est is to return a data structure is
. a package of both the first and the remainder of the structure d retur shou
VIII.i.a --- Next
Y t which i ot be a function osophy, there can In accordance with PLASM A. phi .
" emeht out of a data structure; rat,her it must sehd a requestto I askjhg for th sense takes the hext e
etc; do nothjhg but $ehc1 see, many actors, like next. first
j
rest, length, evs information. As we sha
ts y so that. synta out requests to their arguments -- they act as buck-passers and are defihed
. convenient
: owing request t sends the fol Ne
(next?)
a package (see Chapter ??? for a disctJssio a.nd by cOhvention data structures returh the n.ext element i
: of packagers) together with the rest of' the data structure
6 . Page
P_ge 68 22:09 ) 9 , 8 March PLASMA PR.IMER ROUGH DRAFT
('Iex,: the-next-element
(,.e51: the-rest
: can be easily deflned The buck-passing nex
!! n.xt [
a-data-structure =[ )!!(
) noxt-to: =the-consumer (
]) else-complai,,-to: =the-complaint-dept (
=< the-tonsumer (
=< a-data-structure (
] t? "th.complaint-dept ne (
V III.i.b --- First
d teturn, hot ,in a package, t,he first Another common access function is first ,whlch ,shou
). lections, seU
1
etc for unordered structUtes (co element of an ordered data, strUcture. And by, conventio
' . it should return some arbitrary next element
An obvioUs definition of first would send fir!;t? to its argument:
[first 1 !!
(!!) [=a"'data-structure]
(a-data-structure <= first?]
tnessage and ) d send it a ("'xt requ'est, we cou f the data structure dld not recoghlze the fir!!t?
: unpackage the element
1: first
2
[
],) a-data-structure (elso-cornplain-to: =the"complaint"'dept =[ )!!(
next a-data-structure (
: rtoxt-'o (
) the-first = : ex l ( ) 1: (
) ) the-first
]) -contplai,t-to: the-complalnt-dept elfl (
As will be discussed in Chapter' ???, if you only want to extract the flrst element out of
ext: an-element l (
st: the-rest r (
Page 68
Page 69 22:09 ~ 19 , Match8 PLASMA PRIMER ROUGH DRAFT
the pattern used in first
2
is sufficie:nt.
In fact we would like to combine these two definitions of first, using a PLASMAform
one of them returhs a value othet. than Uate a series of expressions unti y eva sequentia which wil
: he syntax is . nrecogni.ted:) which is then returned as the value of the whole try function .... (
try (
1 expression
2 expressio
expression
n
)
..
is not a prlmitlve actor but engages in more sophisticated message passihgihal1 has b.een ty
e.s t recognjlemeS$a ' ts to interact with actor.s whlch do el introduced so far, using complalnt departn
' ??? section Its definition is postpohed unti
: t ' ete definition of f Using try, however, we can writea comp
first
2
a [
) t a) [=a,-data-structure (olse-complain-'o: =the-complaint-de (
next a-data"structure (
: noxt-to (
) xt: =the-first ( ) a (
the-first
]) tplai,t-to: the-complaint-dept else-co (
I.!.c --- Rest and Length I "
we can define (rest.) to ,tett,trn In a wa y analogous to the deflnition of first,
ts eme umber ofe I of s but the first element, ahd (Iength s) to give a cQunt of the unpackaged, a
" 1 ': in the data structure
~ . ~ ' ,
rest
l
a [
a) [=a-data-structure (
rest? =) a-data-structure (
: else (
next a-data-structure (
: next-'o (
? : next ( )=(
t: =the-rest re (
]. the-rest
Page69
Page 10 22:09 5 19 , 8 March
Page
PLASMA PRIMER ROUGH DRAFT
Iongtht E [
data-structure >=(
Iength? "'> a'"data-structur8 (
: else (
] strutture te-Iength a"dat cul ca (
= culate-length ca [
] e""data-structure "[ >=(
rules a-data-st.ructure (
) 0 ) empty ( >=(
else (
1 + (Iength (
rest a-data-structure (
culate-length is <! function used by length c:a
, ength through the data structure andcalculate the rU
. f ot do it itse n ta-structure c sint:e apparently the d ;
a recursive We could easily use an iterative rather tha ;
il sectlon ition, but iteration won'. be Introduced un defi . ;
;
Pige '11 March 8. 1915 22:09 PLASMA PRIMER ROUGH DRAFT
CHAPTER IX PARALLELISM
es IX.i --- Futu
IX.ii -.- Paral1el S.equences
,.
".
Page
'age 12 22:09 5 19 8 March PLASMA PRIMER ROUGH DRAFT
IX.iii Serializ.eJ:'s
The cOhcept of a serializer is a generalization of the "secretary' concept which was cohceiVed
arbitrate by Dijkstra ahd later developed into "monitors" by Hansen, and Hoare. They are used t
the t ogous to mOhitors i a access to shared actors with side effects. Roughly speaking, serializers are a
1y same way that actors are analogous to SIMULA-67 classes. A serializer is a.n actor that Will al1ow
ow a.1 class .thatWi one process to be executing inside it at a time whereas a monitor is a SIMULA-6
6'7 classes .iri the way onty one process to be executlng inside it at a time. Actors differ from SIMULA
in which the correspondence is defined between an abstract operation on ob jects and the code bodies
that actua11y implement the operation. Actors define the correspondence in terms of. passing 'a message
67 requires that the class.of each bbjectbl:! MULA to the object asking it to perform the operation. S
b je<:t g the type of the declared in the tex t of the progt'am and the correspondence is made by checki
. ass to determine the code body which i5 applicable within its declared c
y one traih [process]is way sWitchyard in whichon lzer bears ananalogy to a rai A .seria
th b . e of efficient .. operation that is applicable t owed to move at a time. A general princip a
izer [monitor] unlocked as mUc::h of the time as itors is to try to keep the seria r serializers and mO
izers havean eneck in t.h.e operation of a larger system. OUt seria possible to keep it from being a bott
pletely $ncase theactor n monitors" [Hansen 1973, Hoa.re 1973] in that they cO " important advantage ove
fJdrari1y t izer. theh te ntrol can possess a seria ed. Thus c to which access is supposed to be contro1
into the actor encased in the serializer, repossess the izer and trave yield possession of the seria
m the y fr ease the serializer with .the rep ly re ies, and fina seria1izer when the encased actor rep
he above beha vior for serializers is i11ustrated by a solUtiori to the readers.:wrfters . encased actor
he . em with one given by Hoare using mohitors contrast our so1ution to the prob problem. We wi
r can prevent the g a protected' act izers using the concept of encasil ustrates how seria examp1e i
. e ity of certain obscure kinds of timing errors from being possib possibi
rm mfJ is cQhstructedby .an expressioh of the f iz.er-n izer with name seria A seria
izer-name senalizcr seria (
) lection-of-queues-for-the-seriClllz4;lr quCUf1I1: cO (
) f 0: recelver-for-messages - a!t er- possessio (
If the actor deflned by an expression of the form given above is sent amessage M then. 1\1' will be. sent
n of the to I'eceiver"for-messages after the activator [process] which sent the message gets possessi
. izer seria
When an activator executes an exptession of the fo11owing form
(e'lqueue the -queue (a!terwardll: the-contlnuation
2 Page
Page Marc', 8.1975 22:09 PLASMA PRIMER ROUGH DRAFT
e"gUeu . and the""queue where it remains dormant until it reaches the front oft it is queued
e-quoue should be served next, which causes the enqueued 3.ctivatOr some.other activator specifles that t
be made conclitional ln the o-col1tinuation. The enqueuing of theactivator ca to tesume with t
: lowing wa y fo
o-queue queue t e (
) e-queue if: condition-for-entering-t (
o-continuation afterwurds: t (
e-queue is false then the activator proceeds dirett1y with .the f condition-for-entering-t
d nbte th.a.t continuation without releasing possession of the s.erializer. The reader shou execution of t
' izers is somewhat different from ..the treatment itimonitbrs. 'We the treatment of queues in seria
originated the above syntax for resuming the execution ofdequeued activators after. Edsget Dijkstra
private communication] poihted out to us that the way in which m6nitors dequeue in the mJd'd.le of, a [
, s ma:de es can ,become bound and other assumptio va,riab monitdr has potential difficu1ties in that loca
for so.me of which may not be valid when' the ehqueued activator resumes execution. The above synta
d the wor affected by the possible chan'g.e .i the enqueue primitive makes manifest the scope of the ccid
n:tln!!lti9n ,,,:c: e execution with. t queued on the-queue and then emerging to resu induced by being el
es ofdur lzer has changed. We are considering using the usual scope ru after the state of the serlct
other very sil'riilat' tlse ved in this case and also a d shift invo wor langUage to deal with the potentia
. d primitive which is described below which is introduced by the yie
uld get ded it is possible to spec,lfy whlch act''Vatdr sh izer is yie When possessiQn of a seria
. possessionnex t
ertqucuc the-queue (
) e-queue if: tondition-for-entering-t (
) sertJe-'lext: another-queue (
afterwards: the-continuatiol1 (
of the y gets possessio The activatol' which is at the head of another:'queue immediate
. seria1izer before ahY other activator
the izer which for cdnvetiience is give icit queue in front of every seria There is an imp
east same name as the serializer. Every activator which gains possession of a serializer must pass at
. . once through this impliclt queue
f the ds possessfon y yie Within the serializer, an expression of the fol1owing form te!'TJporarj
. izer uated without pO$session of the seria e-expression can be eva izer so that t seria
yield the"serializ,er i,t-order-to the-expression (
) presslon I-aft er-re posse 8sioll-tO: receiver-for"value-of-the-e t he (
ext: !"queue serve (
Page 1$
4 Page 22:09 5 19 , 8 March PLASMA PRIMER ROUGH DRAFT
ecutidn uatlng the-expression the next activator on !-queue i8 8erved with e with eva e In para
ing from the point at which it was enqueued. We mentioned above that every serlali,ler h'as an resun
icit queue with the same name asthe serializer. When an actlvator yields possession. of the imp
icit queue in orcler to repossess the, seria,1i!et . It izer then it must ag'ain pass through thesame imp seria
those ilctivat6rs seeking to reposst!u a icatlons to give prlority t may be more efflcient In certaln app
. izer for the first time serializer over those seeklng possession of the seria
eases the ,setializer aftet the Within the setializet, anexpression of the following form re
ue of the-expression has been computed. The value returned by lli!"'sCi!riallz,'r is the vIl1ue of va
. the-expression
o-returfl the-expression izCilr release the-seria (
f!xt: !-queue - le r se (
IX.iv --- Funnels
. ~ Pag ,
5 Page 22:09 March 8. !g PLASMA PRIMER ROUGH DRAFT
CHAPTER X PLAN.S
iiure l $tru Nested. Continuation Contr X.i
X.ii Directed I.:nvooation
5 Page
18 P.tge March 8.1975 22:09 PLASMA PRIMER ROUGH DRAFT
N c VOQATX OTED I CHAP.TER XI . WORLDS AND WORLD-DIR
XI.i --- Frames
, "', '
'" .1
s Page
Page March 8,1975 22:09 PLASMA PRIMER ROUGH DRAFT
CHAPTER XII META-EVALUA.TION
Pa:ge 11
Page 78 March 8, 1975 22:09 PLASMA PRIMER ROUGH DRAFT
S XAMPL ATED CHAPTER XIII .. MORE SOPHISTI
ssageAc.cess XIII.i --- Examples UsJng Apply Level M
XIII.ii .-- A LISP COND
XIII.iii -.- Parallel .And
XIII.iv Total Quote
uation (a.s does There is a quotation mark which does protect an entire expression frotn eva
the LISP quote), which is written as 0 . Thls quotation mark is known as IItota1 quote", Thu!I the
value of
1 + 2) * o(factorial (10 - 4
is
4 10 (square-root ( 3 * (factoria (
These quotation conventions make the construction and analysis (jf programseasier. !h
yte struct arid ana PLASM A than in LISP because it is easy to write efficient powerful patterns to co
. CONS, etc R, APPEN ike CAR, t evel functions ow y on ving to re programs instead of h
e g owing actor which converts expressions written using a. sit e consider the .fo1 For examp .
case let. . construct (which we noted was In essence. an "abbrevlation") and returns eqUiva1ent
: expressions expahded !nto a receives statement
Page 78
page19 Match 8. 1975 22:09 PLASMA PRIMER ROUGH DRAFT
:: expand-single-Iet [
) body = e> '(let {[=nam8 .. =value (
>= value ('
]) e> I"'name body
The the value of
2 '" x ( expand-single-Iet O(let {[x = (y '" y (
would be
y '" y) "'> (e> =X (2 '" x
I.v --- A Meta-Ciroular Defini.tion qf' eons".t811 XI
we will preseht a "meta-circ:;ulat" defif1iti.Of1 of the As an example of a definition using a ce
dp a ve to use, but we WIII d without having ii. ce y we cannot define a ce scell actor. Obvious c
. definition that is not entirely vacuous
As mention.ed above, the contents actor sencls a request to a .ce First we define eontents.
asking the cel1 to send back its contents. There is no way in which contents . can teach in. and ta,kethe
. osophy. Therefore we .c1efine the actor phi ate a f. That would vio I by itse contents out of the ce
: ite request ts to send out a po eonte .
tents e co [
] e> [=a-eell (
]? a-c811 <= contents (
$ ike this. For example. theactof As we wil1 see, many actors In the system are buck-passers
y send messages to their arguments requesting different. types of simp eval, miltch, etc. a first, print
the kl1ow1edge beha vior. This practice tends to modularize knowledge about dlfferent structures; al
s-tell wI11 co.ntaitl .a ists isin the script of the list actor. In our case the definition ot tO about
atge be added .to i s beha ve. Another ad vantage is that new stru\:tures ca edge about how ce know
system without requiring changes to any existing actors. Chapter ??? discusses this issue. of distriblJted
competence in more detal
We return to cons"cell and present our first attempt at a definitiol1:
Page 19
80 March 8. 1975 22:09 PLASMA PRIMER ROUGH DRAFT
ns"<:o"l E c [
] e> [=initial-co.ntents (
let (
the-<:ell = (cons-<:811 initial-c:ontents [{
ases <:(
? a> contents (
) Sthe-cell
] E> [+- =new:"contents (
]))))) the-cell +- new-contents (
, Aes b actors, and hence of course a ook c1ose1y enough, it turns out that a In fact, if you
are receivel's, There is no way to define .an actor whlch is not a receiver of transrriissiohsj however this
. ay not be obvious yet
with this A probte ns-1:8"1' yze our defin.ition of c s, we are ready to ana To return to ce
definition is that When asked to change contents, cons"celll returns not itself but the inner .c11 that {t .
rna - rather we wou.ld like to tet d to the outside wor ease that ce is using. B\.lt we don't want to re
at the momenthas 1 ns-celll' But this actor, the body of cons-ce handle on the body of c
. p often name. This situation of all actor in a definition needing to be able to refer tQ itse1f comes
em by giving thE! body a We c;ah construct a definition of .cons-cell which solves theprob
: ows n.ame using ( ... a ... ) as fo
cons-ceIl3 E [
E> [=initial-contents (
let (
}]) initial-c:ontents the-cell = (cons"ce [{
itself E the-ce (
c:ases (
? tents 5) cO (
) St.he-c:ell
] E> [..:. =new-contents (
) the-cell +- new-contents (
)) itself the-ce
we have ut fina,1 vetsion unti de1iiy Even this Is not the best we can do, but we wi1
. introduced the pattern of the next section
page80
p.age 81 March 8. 197IP 22:00 PLASMA PRIMER ROUGH DRAFT
OTIVE RSP ICAL P XIII.vi --- HISTO
. .
us constructed by Alonzo Church originated the modern formalstudy of The lambda calcu
Sically defined by theit I ob jects are intri us of Church a cu intrinslc computation. In the lambda ca
is beha vior. [The ohly ob jects in Chutch'ssystem are lambda expressions and the only opetation whic
ur We have t;()n(;ehtrat owed to be performed on a lambda expression is to send it. a tnessage al
g atea of programming systems and the theory of programmit1g ih the follow1 wotk in the genera
: areas
to i.ssjo 5 communication primitive [called actQr tra Developing a universa
. sages ssingm.e trol strtlctures to be recoghized as ! pattern of p co e a enab
udes the c Developing a mathematical model theory of cotnputation' that i
th.e Scott ur model of computation difft:!rs fr . cultlS as a special case lambda-ca
of coritlriuity. We h.ave io model of the lambda-calculus which Is based on the .no
1 t cide usal and i g the noti-on of oped axioms for our new theory usi deve
.] 1975 1973; Greif. anc:t Hewitt ts [Hewitt et. a evel S betweel reJatiOI
tetms of message environment is defined' i Communication wlth an externa
.$ u catct.i ambcla form as is the case in the passing instead of reduction to a norma
.$ izing Scott's notion of continuity to systems with. side-effect We are genel'a
of computatio structures. In our mode ism. and arbitrary contro le para
the basis of the tinuity is a property .that s,ystetns can be proved to .hotd cot
. itive actors for the system axioms for the prl
at methods oping methods to specify whatan actor 'is supposed to do as we Deve
is ishing the task ,using one universa.1 forma fora.ccomp ,
d effects, a ism, concutrency, side e ar primitives for paral oping modu Deve
. chronization sY
, guages'[C,hUtch a us Use of intrinsic computation has been pioneered in th.e Lambda Ctlcu
and rhe SMALLTALK langUage of McCarthy. Landin, Evans. Reynolds. Burge. etc.J. SIMULA-6
ost y we adopted the point of view In SMALLTALK of defining the behavior ofa: an Kay. Initia A
d imitil1g sically. However. we have come to find the intrinsic point of view too I objects intril a
owledge be usedinstead. Jim Sta.hsfield o.f 'kl e of tt10dular distributiol OW propose that the princip
so makes this point in his forthcoming Ph. D. thesis. Information. tan be represehted in vatfous ways a
e to represent knowledge redundantly with different uses of the actor system. Often it is desirab a i
e tnight choose to disttib'Uteit aces. How o p edge appearing in different guises in severa same know
. Havingasystt! edgetan be put depends on one's purposes and the various uses to which theknow
se be ere jt ca edge anyW e capability of putting know in. which every ob ject is an actor gives us t
era.tite the edge is OUr Use ofactors to ge ar distribution of know An important example of the modu
Pa.ge81
82 ge P
22:09 t; 19 , 8 March PLASMA' PRIMER ROUGH DRAFT
81 '. , 1973]. Worlds are actors which handle put. get, and contexts of QA-4 into worlds [Hewitt et. a
. messages
trJ'.tK. -- Relationship between PLASMA and ,SMA XIII.vi.a
The last few years have seen rapid advances !n the development of formalisms ,forthe
ished procedural embedding of knowledge. The early work on PLANNER was done at MIT and pub
n 1970 a gfoUp of interested researchers [includin'g Peter Deutsch, Richard Fikes,l, Qart . in IjCAI-69
Hewitt, ]eff Rulifson. Alan Kay. Jim Moore, Nils Nilsson, and Richard WaldingerJ gatheted ittPajafO
d tered the ,fie1d a Dunes to compare notes and concepts. Slncethat time hew researchers have e
if'ied y rapid with many new concepts and cOhstructs being prbposedj progress has been extreme
: y close contact and generalized. The various researchers keep in fair "
in which he emphasized the impotta:nce November 1972, Alan Kay gave a semihar at MI I
sUch as WclS dOheto of using intentional definltions of data structures and o,f passihg messages to the
, data structures" in the lambda calcUlus languages of Landin, Evans a limited extent for the "procedura
ly y the data type itse1'f, re'a y ih SIMULA-67. His argument was that on o1ds and extehsive and ReYI
to procedutt sly givensome attehtio ement any given operation. We had previ6 knows" how to imp "
ready had knOWh how to imp1ement .tl1e LISP data structures in our own research. For example we a
. us cu ambda-ca consfunction in the
11 receitJ8 'J& tind ;
e"i'ige receltJe ;
I ;
air the me"ate i ;
returh 'J& ;
e htel&lage i. 'cdr if ;
h 'Y retU ;
nt t ., e meB.ate i if t ;
,,,. a left parehthe ; .. p ;
pnttt:t ;
01 ';'e dotted pair ht the d p ;
tprint y
, prlh' a right paren,he.i ;
== tons [
) y lambda (
) lambda (message (
cor.d (
) equal message 'car
) x
) message 'cdr equa
) y
) t ri equal message
)"(" t pri (
) t x pri (
)":" print (
) print y (
])")" print (
il) 'c:ar) Is 3. However, we Were Under the miscoficeptioh thtt 3 s For example c:o
though they have though It procedural data structures were too inefflcient to be used uniformly a
. certaln advahtage,S
ecture strtlck a. respohslve note because of thls previous history. We immediatelysaw Kay's
Page.82
Page 8:4 22:09 5 19 , 8 Match PLASMA PRIMER ROUGH DRAFT
ote embedding of knowledge to 'construct how use his idea to extend the. concept of procedura
eofthe effect to extend the prihclp powerful PLANNER-like systems since the fundamental idea is I
ow)edge to data structures. In effect each type of data structure becOmE!$Ci gof kl procedural embeddil
d extencls .. the fotces a ittle plan of what to do fOI' each kind of request that It re<;eives. Thisrei
ly expressed as fundamental paradigm of the PLANNER-like systems which (an be schematica
PLANS =HIGH LEVEL GOALORIENTED PRdCEDURE.S
streatn oriented interpri!!ter to ed SMALL.TALK with a. toke Kay proposed a language cal
certain ways to sM ALL T ALK had beef1 ar i implement these ideas. Token stream interpreters simi
oped by Peter Samson at M.I.T. and Vaughan Pratt at Stanford. For purposesof previously deve
1 . comparison we give the definition of COhS in SMALLTALK. The definition makes use df %and
lowing '1,i which are two special SM ALL TALK operators. The operator % to'oks to see if the token fo
the program is literally the same as the next element in the message strearn. If 50 then it. rep1aces.the
thel'rless.age meht serts false as the fi.rst e1 wlth trtie. Otherw,se it i ext element In the token strean
r fll...I.f1 he operator ? requires that the next token in the rnessage strearn be either .rut . stream
e n t t th eted from the message stre,am .. If the deleted token was ti' either case the next token is de
and,.ifthe e oth.er On t owing the ? operator in the 'program is given contro next expression fo
operator is skipped se then the next expression in theprograrn following the eted token was fa de
. owing it is given control fol over and the expressio
and :y ce hall two rnemory cells, ,tamed e class cons such that each iJlsfa de[ine ;
c,e wit ate. ah i,lsta if this callis directly '0 the cla#s de[inition, cr ;
d behtlvior de[iJled by.the class de/ini'tio its OWfl iJlstafice nternor.r, al ;
d femOfJfJ it RigJl :t' the value o[ the [irst to.ken in the message s'ream d a. ;
bt>e it assig1l x ,I,e value o[ the [irst toke'. in the rnesilage Btream aftdre ;
Y aluei t th assig ;
the mellsagestreo the iJlstaflce 80 that it can take [urther t(}keftll [ro active1.r refur ;
re4.m emes'sag rorn , e fir/lt token is literall.r car, ,hen remove i i[ t ;
:t' ety retur O,rtd acti ;
m or 'he meS80,jjtJ .ire else if ,he firs' token 111 literalty cdr then remove it ;
:y tttt elyr and acti ;
d iea . en d'elet t ir!!' element in the token lI'ream ill pr else if the ;
' paren'hesili a '(J rin en t ;
tketfJ ri'ht . 0 ' te". x ;
: thedot pn he ,:
;/ tBel tell y 10 p ;
gh" parenthe t a ally pri i artd ;
C:8". cdr. or prlnt o e rnesBage stream ill else if the Jlf!:t't toke ;
e class in.tancfJ then paBsively return SELF whichi ;
S : X y to C
? isnew (
("x 4- :.
"y 4- t.
) SELF !
? c'ar %

? cdr %
) !y (
? t ri %
. print ("(
. t pri )(
. t t', pri
. t y pri
t 1') pri
For example the following expression will print 3:
ear pril1t i 3 S CO
Page 83
84 March 8. 1975 22:09 PLASMA PRIMER ROUGH DRAFT
era1 dbtain a ge In November 1972. Peter Bishop and Carl Hewitt were working to try t
em b ikep'f ution to the contt'ol structure problems which had continued to plague PLANNtR so
" dund 'ipossibil'ity lis'ts ution oriented a solving systems for some years. Sussm,,:n had proposed a so
ists" isthat the em with Sussman's "possibility whichwe felt had vel'y serious weaknesses. A prob
ooking at their contents using try-next can cause unfortuhate global side-effects. These simply
ook at the possibilities, make CONNIYER. side-effects which result merely from attempting to
e ALK ha.ve .thesa he token streams of sM ALL . programs hard todebug and understand
Kay ted dut t side-effect problem as the possibility listsof CONNIVER. After the lecturej Hewitt poi
ted ihterpreter ved in his scheme for a token stream orle ems invo structure prob the contro
AI..K By December 1972, We succeeded in generalizing the message mechanlsm of SMALL
and the.previdus CA1.L zer, and Mltchel the port mechanism of Krutar, Ba and SIMULA-6
ved the izatioh so I to a universal communication mechanlsm. Our genefa statement of PLANNER
. ALK.W.e structure problems that Hewitt pointed out to Kay in the desigli of sM ALL contro
ei1denti developed the actor transmisslon communication primitive as partof a new language-inde
el of machine-independent, behavioral model of computation. The development of theactbr th
. contribution to this area df research computation and its I'amifications is our principal origina
d ry. PLASM' A a ance . due to this hist Although they bear a certai\1 family resemb
ALI( are rather different systems. Many of the differences .have come about becatise SM ALL
ie\te that SM ALL TALK and PLASM A were created to serve different purpdses. We be
SMALLTALK may be better sUited than PLASMA for spme of its app1ications and that ton'versely
ems in system desigh ctlme from t prob ications. Difficu PLASM A has certain advantages for our app
ize the interaction of various design goals. In our reseafch prog,fa:m,. the attempting to rationa
forexpressing y a convenient fofmalis t is on . development of PLASM A is not an ,end in itself
dep.endehtbf ationships which have an existence and importance that Is comptetely i semantic re
ehta1 c::h.arai::ter PLASMA. We feel that our "esearch on actor semantics has a deeper and mdre funda
PLASM A is a system dedicated to the direct realization of this semantic base. Becau'se of tt1e
, side-effects in its token stream message passing and because it does not have a uniform actor basis
SM ALL T ALK is not a sUitable language for our purposes. For purposes of comparison, we give the
: ow definition of cons in PLASM A be
' o .bf1 thtl actor cons iB defined ;
tB whichwe Bhall ca'll x artd y ence with two elemo receitJe a lIeq ;
rn an actor which ha' the foltowing behatJior re ;
if dB'A:ed /o,.i;, car ;
rt!ply tvtt.h:t ; .
if 4Bked /orlt. cdf' ;
repty tiiith.:y ;
rlIel/ '0 a cUBtornt!f' 0w YO if aBked to ,
" e t6 e cu t tel ;
, n hat you are.a c ;;
,. :t aJl your Ca wi ;
f ctlr h y aJl y ahJ. w ;
84 Page
ns E! c [
] E!) [=x =y (
cases (
? e) <:ar (
) x
? E!) cdr (
) y
) ow: "the-customer s (
tell the-customer (
) is-a: cons (
) has-a: <:ar x (
has-a: <:dr y (
Page 85 March 8. 1971; 22:().9 PLASMA PRIMER ROUGH DRAFT
Our definitions of car and cdr are given be1ow:
d 'f).be the acto,. clJr iB delin ;
li,t receive ;
olik it 10,. itll.bb.r :
[clr E!
(E!> [=the-list]
(car? => the-list]
d,. ,i. delined to .btJ he ftctor
e a li.t recei ;
081t it 10" la. cdr ;
[c:dr E!
(E!> [=the-list]
(c:dr? .. > the-list)]
. 3 e the expresslon (cllr (<<:ons 3 nilevaluates to For examp
opment af the actor model of owing were the maln tnftuences on the deve The fo1
: computation .
. ggestion by Kay that procedural ernbeddin.g b.e TI.e sl
u5 ur ptevi the context .of ded to cover data str(lctures i extel
cralize tl.e worl< by Church, Landin, Evans. and npts to get atte
" al data sttuctures ctio olds. 011 "fu Rey I
up and text of our previous attempts to clea e cO TI .
,. Mitchel di eralize the work on co-routine control structutes of La gel
. d Sussman olds, Bobrow.Wegbreit. al tar, Balzer, ReYI Kr
ce of Seytnour Papert's"little m3n" metaphor for uel e il1f TI
. in LOGO n.putatiol cO
s and complcxities. of capability.based e limitatiol TI
smiss!on Js ii. effctt an nes. Every actor trat c scl protectiol
actor sic protectio intril call efficiently providing a nail terdo il
eS machil
ti()ns of PLANNER ner ce developing previotls g The experiel
tia11y nposers of PLANNER71]. Essc strtlctor.deco particu larJy the cO [
s) was sio guage [together wittl some extel e whole PLANNER71 la tl
Davies. in POP2 at the ,Uriiversity of ted by JuJial nel imple
burgl Edil
y and technical osop phi y helpful in discusslons both of overa Kay has been extreme
ationship between actors and sM ALL T AtK t:ome details. M ost of the inslghts given below on the re
Page S
Page 88 March 8, 1971) 22:09 PLASMA PRIMER ROUGH DRAFT
s the 3 to discu ay in August 1973 at the time of IJCAJ as a direct result of Hewitt being able to visit
. . various issues with him and the members of his group
. Below we discuss a number of differences .between 'PLASMA and sMALLTALK
cl1ildten of.altages
li
e by ly SM ALL TALK is designed to be a language easily usab Pragmatica
. whereas PLASM A is designed to be a transparent formalism for expressing actor cornputations
y t e PLAS M A is designed to be a system in whjch any effective actor system can be conve
actor semantics frorn the very begihni'ng g PLASM A basi i implemented. Our contributio
$ d J\.ay's. PLASMAi ook between o.ur projetta content and out differences j ta introduced fundame
u.r for pfograrnrnin:g designed to be used by experlenced programmers. It also serves as tl1e language
I cleanliness of bel1avi.oral definition Qf a apprentice which gives, it a furtl1er blas toward exceptiona
eof .th language constructs. We have tried to deslgn PLASMA so that as many properties a5 possib
the structute ofthe beha vior of an a.ctor system implemented in the language sh.ould be manifest
. code
' 'Programs in PLASM A have a uniform actor basls. Every iden.tifier !n aPLASMAptogtarn
structures, procedures, messages, and continuations are all beh.aviors refers to. an actor. Ope"ators, data
whicbare staJ1ces [in the sense of StMULAw6 ement. The classes and i which actors can imp
1n pLASM A. to SM ALL TALK have been subsumed by the single concept of anacto fundamenta
ves actors which are sent messages of theforrn Programs !n PLASM A are themse
eval: an-.nvlronment) during evaluation. In fact the definition of the eval operatot for PLASM'A is the (
: following
= eva [
] ment iflg =the-enviro the-expression u. =[ )=(
]) the-expression (:: (eval: the-environment (
he .. ity The above scheme has the advantage that PLASM A has a bUilt !n extensibj
: f}tJal ( ism can be extended by simply defining more actors that receive messages ofthe for forma
Ptograrrisin g eva1uatio ALK are sent as. token streams duri an:-environrnent). Programs in SM ALL
PLASMA are actors which are expected to be already parsed [by the actors associated. witl1the
ves the referehces ent which reso ed in an envifon and instal characterswhenthe program is read in
. I the free identifie,-s in the programs to a
is entire1y The fundamenta I primitive of ACTOR formalisms[ACtOR 'rRANSMISStON
to the ititerpreter of free of side-effects Whereas the stream token message passing bUilt i
e. Throughout the whole PLASM.A system we SM ALL TALK has side-effects which can cause troub
ly a ve attempted to a void commitment to gratuitous side-effe<:ts while retaining tl1e ability to. natura
f incorporate side-effects where they are desireable. Actor transmission subsumesthe opetations
function return, and co-routine cal1. Using explicit transmissions. arbitrarycotitto1 function ca
ALIt SM ALL structures [patterns of passing messagesJ can be efficiently constructed using PLASM A
has three kinds of message transmission primitives bUilt into its interpreter: one kind of function calt
and two kinds of return [active and passive
Page 86
P.ge s March 8, 197" 22:09 PLASMA PRIMER ROUGH DRAFT
of message nessageswhith are a different leve for system level PLASM A. makes provisio
e of a system level messageis g system tasks. An examp passing for accomplishi
lected using t garbage collection (for actors t!ot co eme be .used to imp e-overlord) which ca recycle: t (
s. When an actor A transformatio oba reference counts] , storage compactification, and certaih other g
message of the above form then it first asks the-ovEtrlord for a place to recytte eve is sent a system
turn sehdsba.ck ove.rlord which i y knows about to th icit of the acto!'s it exp itself to, then it sends a
e ed versiof1 of itself to. t ly A returns the recyt es itself; and fiha the recycled versionsj recyc
eht cOhtinuation which came in with the original recycle message. In addition tQ being I.isefu1 to. tmple
y repJace 3.1t the ector, the mechanism .can be used to giobal e garbage co e extensib a programmab
e kihd with other smarter actQrs. Provided that the behavior of each actors of a certain recognizab
actor that is replaced is contained !n the behavior of the one that replaces it, the transformation isa
eto be ab conservative extension in the sense that no information is lost. I. E. the new system wl1
n ttacing and ! realize any beha vior that could be realized from the old system. This can be usefu
. . monitoring the behaviol' of classes of actors
l to In PLASM A we have generalized the pattern directed invocation of PLANNtR
vocation 011 the b.a.sis of a WORLD DIRECTED INVOCATION [Hewitt et. al. 1973] which is i
maY nicro-world. We foresee that the furthet develbpment of World ditected invocat.lo fraglneht of
t ro.le in future development of PLANNER-like languages. Within th.e actor model of playan importa
edgeta d is fot actors which have the know be us Qwledge ca computation the only way a piece of k
tion netwt>rklt 1n be sent messages which cause them to act on it. We forsee that progtamming distrib
tlon as belng important for effective modUlar distribl.ition ot worJds to handle world-directed invoc
. knowledge
:R tV XIII.vi.b --- Relationship between PLASMA and OON
y a pattern of passirig trol strtlc.ture is. simp putation, cOI of co In terms of the actor mode
S ch messages. The actor view of control structureis superior to the ohe espoused in languagess
CONNIVER [Sussman and McDermott 1972]. Contro1 structure in CONNIVER is basedon the
: following potpourri of constructs
PAL-GEDANKEN style nonlocal gotos
Updating Bobrow-Wegbreit style activation records
IPL style generators
QA4 style contexts
t-in side-effects ity lists with bui Possibi
: owing advantages over thatof CON.NIVER structure has the fo Actor contro
Page 81
88 22:09 5 19 8
1
March PLASMA PRIMER ROUGH DRA,FT
yzes the problern of cdntto structure ana ce: The actor view of contro Cot.ereI
em of transmitting the rlght message actor to t,he right targeta:ctof structure as belng the prob
y y incorporates a11 cutrent at the right time, We can show how the actor paradlgm natural
d utines, backtracklng, a t uding Iteratlon, recursion, co known control structures inc
ism, A serious problem with the CONNIVER approach to csntrolstructut,e is that,the e para
es must thlnk in terms of lowlevel data structU programmer [whether human or machlne
. ttgtask eyant toth,e prograrri ists which are irre ity such as actlvatlon records or possibi
ows the programmer to think In terms of the behavior ofobjects that The actor approach a
ne y occur in the domain belng programmed, For exampld in a blocks wor,ld ,domainl natura
, d send message to actors which modeled the behavlor of ',blocks, stacks of blocks,archE!s wou
d progta:m actors whith behavedlike d domain, one wou language wor etc, In a natura
mer have to d the progra words, noun c1auses, verbs, direct objects, etc, At no ppint wou
," concepts such as "a-liI11<5 eve ow think in
y free ,6f trillsic S,ide Effects: Actor transmi'ssion 15 ehtire II Freedom frol
side-effects [an actor programmed In PLASM A can have abehavior that va.ries with ti,me
s], The control structuresof CONNIVER which are ,based y if' it makes use of ce on
01' , 1'inks d conttd ements from possibility lists, updatlng access links a eting e d de entering
. to them es hlive intrinsic side-effects bUilt i variab dating nonloca activation I'ecords, and ul
es of ModllJarity: The contl'ol mechanisms of CoNNtV:ER violate princt'p
arity and frustrate the design goals of PLASMA listed abbve in a varietyof ways; T.he modu
hescheme . this re5pect pable i arly cu standard GONNIVER co-routine scheme is particu
g a "genera1itedtag
il
T which is adopted from PAL and GEDANKEN] COhsists !n returni [
nicate with T ,by ater tlme another program can tomm from a program so tha,t at some
: owing fotm executing CONNIVER expressions of the fo ,
e o{o. ullylj n i8 the na aBsign n the value vl where {hope ;
eneralizetl tttg, t e La,idin style cal variable I
ichcteaiiJd t gran.1 that, called '''e programw me pr 8 r
he midJ.ie,ot'he to back i,lto nlocal g jexecule a PAL-GEDIJNKEN style
in' alter.'heioK artd resume executioH.at 'he p at created program t ;
(csetq !! T)
(go T)
1,
cause non-reprodUcible tirriing ettorsiri y, the above mechanism wi Unfortunate
y a "s.o oc wi in paralle ism, Two processes communlcatil1g with the ptesence of paralle
: rs owing sequence of events occ ose when the fo
Process2 ProcessJ
(csetq !! T)
csetq !! v2 (
go (
(go T)
Page 88
Page8,9 March 8. 1971' 22:09 PLASMA PRiMER ROUGH DRAFT
if the JI(!Jtsi l1ce of piaf' bs in the occur evel d of bug ca Tlte above kil
aref'u'j. 'the 15' notvery " e "generaJized tag e routille with tl nrner W'IO codes tl progra
ed whith desires to subroutine Is ca1 obbered if be c e n wi ue of the variab va
communicate with T, Thts may destroy the preVious message to T before it has beeh read
. Dijkstra has remarked that the use of the goto is associated with badly struttUred programs
y We concur in this jUdgment but feel that the reason is that the goto is not a suffitient
' g' with t a1t> not be se powerful prlmitive, The prQblem with the goto is that a message Ca
a y thls p'roperty of actor transmission that makes it int t is exact , e target control to t
' , primitive universal communicatio
NNIYER the' C SuitabiJity for a Programming Apprentice: The side-effects i
control structure primitives force the programming apprentice to go through the trauma ,of
lcated deduction,s must be call, Very comp ctio every fU McCarthy frame shift
has thesa,me variable stil performed to determine simple properties [such as whether a IQca
t PLASM A e inspection from the cod,e of an eqUiva that are eVident value as before
structure. it has been progl'am, Because of the cleanliness and coherence of actor cohtro
semantic model [Greif and ,Hewitt 1971] on whichtob,ase op' a usefu e to deve possib
meta-evalua.tion in the programming apprentice. We conjecture that CONNlViER is hard ror
,the people to deal wlth for very similar reasons as the ptogramming apprentice becaus
he programming apprentice is fQtced to ," e-like prog'ramming apprentlce is somewhat "peop
lke" because when it encounters an anomaly it has to tty to exp1ain the at "peop1e be somew
, nature of the anomaly to the programmer in terms that are familiar to her
, ttolmechanisms h5: Because of its primitive co Readability of Progra
t ug. Furthetmorej it is very diffitu d to de t to write a NNIVER programs are difficu C
NNIVE gs have been shaken out, C f the b for others to read the code even after many
n that is very appatentto the infinite 100ps for no teas programs are prone to going int
,' progl'ammel
ess CONNIVER represents a substantial advance o"et MICRO-PLANN'ER ih Neverthe
easilybe performed. However this increasing the generality of goal-oriented computations that ca
ving. It em so evel of the language of ptob incl'ease in generality comes at the pl'ice of 10wering the
ementation terms such as "possibility lists" and"a.Jinks"., We imp forces Users to think in 10w leve
s diVid,ua propose a shift in the paradigm of problem solving to beone of a s()ctety ()f
g tnessages, Within this semantic paradigm PLASMA attempts to, att asl. icatil1g !!.r passil commuI
' . m for expressing desired behaviors within this paradigm e transpal'ent medi exib f
Page 89
Page 00 March 8. 1911) 22:09 PLASMA PRIMER ROUGH DRAFT
ACKNOWLEDGEMENTS CHAPTER XIV
igence and sored by the MIT Attificia1 Intet The research reported in this paper was spo
. sorship of the Office of Naval Research der the spo d Project M AC ul Laboratory a
d have been completely impossible wlthout, the The progress we have made on actors wou
s and questions of numerous MIT students. Ben KUipers, Howie Shrobe, Keith Nishihara contributio
e much of i Brian Smith, Aki Yonezawa, Richatd Steiger, and Peter Bishop, and Irehe Greif have do
based t tothe problems of tonstructing knowledge eva e and re igib the work in making actors inte
f systems. Irene Greif is doing exciting work ih extending behaviorat setnantics to the a.t'ea
e . :Brian l ro t id foundation. HoWieS a more so inter-process communication and putting semahtics
" ultitude of "throW.iaway r e, and Peter Bishop have contributed tCl the Smith. Todd Matson, Roger Ha
. emehtations through which have we debugged many of our ideas imp
Page 90
Page A March 8; 1975 22:09 PLASMA PRIMER R'OUGH DRAFT
S ) APPENDIX A LIST OF CORRECTIONS AND .ADDITt
SUBSTANTIVE ISSUES :
. ete and wrong lots .of places The discussion of matching is incomp
. . Needs to be worked out much better
Write a sectioh oh falting off of parentheses
Make cross-referencing and indexing work!!!! (no more ???IS!)
Write the deta iled pattern matching section, moving 'iafter" from
the informal introduction to it.Include a discussion of
"(optio'lal: ... )".
warnings to the reader about !;ections whic:h get super Put i
. hairy so that they can be skipped .
. edgements WritEl IIcknow
Complaint departments aren't quite worked out.
Do packagers really evaluate their arguments?
d be some indic:ation beside definitions whieh have There shou .....
definlte bugs and are correc:ted In futur. pages, so that
someone stumbling across it won't try 10 figure .out how
! it can be right
Write a whole chapter on arithmetic
Needan example of c:o-routines in the c:hapter on non-rec:urslve
c:ontrol structure. Same-fringe?
." ain it and "try SP COND, al1d exp es: Write L Examp
. es section D.fine "option81" and "unpack" in the examp ..--
. more comparlsons with LISP Put i
off e and ri system-Ievel messages, lik8 reeyc: Write a chapter
Page A
Page B 22:09 S March 8
1
t9 PLASMA PRIMER ROUGH DRAFT
. terpreter Chapter the I Discuss and define "Ceses" i
YPOGRAPHICAL ERRORS ING AND MIN.OR EDI
.& o ..... J. ... where appropriat Search for ...... .f, .. and change
O PUB MACROS CHANGES
. Footnot8s should print numbers, not ttars, .and be elevated ......
e 18ft e li abs not to start a paragraph If there is only O Fix -"'-
o the bottom of the page Subsec can !!tart a new !!ubsec:tion too close .
Page B

Das könnte Ihnen auch gefallen