+ All Categories
Home > Documents > AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are...

AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are...

Date post: 14-Mar-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
16
AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals for ALGOL X l, Gerhard See gmulle r The proposals made here are a preliminary and informal condensation of some ideas which will be presented to the members of WG 2.1 in due time, hopefully before the next meeting. The discussions aim at a better understanding of certain features of ALGOL 60 and, at the same time, are meant as contributions to the development of ALGOL X. . Types and declarations. (Eight types; "static" type checking; self-classifying notation for constants; object character set independent from the set of basic symbols; initialization; structure indicators; constant declaration) As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class, e.g. arithmetic operators. To achieve the full efficiency effect of types, rules for expressions and statements have to be set up so that type checking need only be done a) at compile time, and b) at entering a procedure body at run time[l]. (This means, for instance, that the operator power has to be redefined, namely that only positive integers as exponents will be allowed.) For this proposal the following basic types are assumed: integer, real, complex, .boolean, character and/or string, bi._t, label. Variables of these types take on constants of these types as their values, where for instance with the arithmetic types no l-l-type- matching is necessary. The permitted cases can be derived from the principles of type-checking mentioned above. For constants of each type a self-classifying notation should be adopted. This is not true in ALGOL 6o, where labels are denoted in an unfortunate way, namely as variables of undeclared type or as integer constants. We propose. label constants :: = ~ <identifier> ~= <unsigned integer > . The set of values for variables of type character should be independent from the set of basic symbols of ALGOL X. It is proposed that it consist of the hardware characters of the machine the ALGOL X-
Transcript
Page 1: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 7

AB21 S WORKING PAPERS

AB21 S 1 S o m e p r o p o s a l s f o r A L G O L X

l

G e r h a r d See g m u l l e r

The p r o p o s a l s m a d e h e r e a r e a p r e l i m i n a r y and i n f o r m a l c o n d e n s a t i o n of s o m e i d e a s which wi l l be p r e s e n t e d to the m e m b e r s of WG 21 in due t i m e hope fu l l y b e f o r e the next m e e t i n g The d i s c u s s i o n s a i m at a b e t t e r u n d e r s t a n d i n g of c e r t a i n f e a t u r e s of A L G O L 60 and at the s a m e t i m e a r e m e a n t as c o n t r i b u t i o n s to the d e v e l o p m e n t of A L G O L X

Types and d e c l a r a t i o n s (Eight types static type checking self-classifying notation for constants object character set independent from the set of basic symbols initialization structure indicators constant declaration)

As in A L G O L 60 types a r e a s s o c i a t e d wi th v a r i a b l e s O p e r a t o r s m a y be d e f i n e d to o p e r a t e on m o r e than one type c l a s s e g a r i t h m e t i c o p e r a t o r s To a c h i e v e the fu l l e f f i c i e n c y e f f ec t of t y p e s r u l e s f o r e x p r e s s i o n s and s t a t e m e n t s have to be s e t up so tha t type c h e c k i n g n e e d only be done a) at c o m p i l e t i m e and b) at e n t e r i n g a p r o c e d u r e body at run t i m e [ l ] (This m e a n s f o r i n s t a n c e tha t the o p e r a t o r p o w e r has to be r e d e f i n e d n a m e l y tha t only p o s i t i v e i n t e g e r s as e x p o n e n t s wi l l be a l l o w e d ) F o r th i s p r o p o s a l the fo l lowing b a s i c types a r e a s s u m e d

i n t e g e r r e a l c o m p l e x boo lean c h a r a c t e r a n d o r s t r i n g bi_t l a b e l

Variables of these types take on constants of these types as their values where for instance with the arithmetic types no l-l-type- matching is necessary The permitted cases can be derived from the principles of type-checking mentioned above For constants of each type a self-classifying notation should be adopted This is not true in ALGOL 6o where labels are denoted in an unfortunate way namely as variables of undeclared type or as integer constants We propose

label constants = ~ ltidentifiergt ~= ltunsigned integer gt

The set of values for variables of type character should be independent from the set of basic symbols of ALGOL X It is proposed that it consist of the hardware characters of the machine the ALGOL X-

AB21 p 8

compiler is written for A constant of type character is denoted by including the single hardware-character by some sort of quotes If the hardware character has no representation on the medium used for the source program then

( ltunsigned in tege rgt )

i s to r e p r e s e n t the c h a r a c t e r [2] The i m p l e m e n t o r has to s p e c i f y the c o r r e s p o n d e n c e b e t w e e n i n t e g e r s and those h a r d w a r e c h a r a c t e r s E x a m p l e s

A vv _j vu

Iv I v ( 6 4 )

S t r i n g c o n s t a n t s shou ld be t r e a t e d a long the s a m e l i n e s The q u e s t i o n w h e t h e r c h a r a c t e r a n d ] o r s t r i n g t y p e s a r e a d v i s a b l e i s not dis c u s s e d h e r e

The s u p e r quote o p e r a t o r m e n t i o n e d in [3] shou ld a p p e a r as one of the b a s i c s y m b o l s of the l a n g u a g e A s e c o n d one has to be i n t r o - duced in c a s e a c h a r a c t e r deno ted by an i n t e g e r as above is a l lowed to a p p e a r in a s t r i n g c o n s t a n t

In c o m p a r i s o n wi th A L G O L 6o type d e c l a r a t i o n s shou ld be g e n e r a l i z e d in s u c h a w a y tha t t h e y a l low

a) i n i t i a l i z a t i o n b) a r e m a r k on the m i n i m u m n u m b e r of d e c i m a l d ig i t s to

be c a r r i e d wi th ( for a r i t h m e t i c t ypes only) c) a r e m a r k on the s i z e of s t o r a g e which wi l l be r e s e r v e d

f o r the v a r i a b l e c o n c e r n e d ( for c h a r a c t e r s t r i n g and b i t only)

d) a way to i n d i c a t e t h a t the v a r i a b l e i s u sed only as a n o t h e r d e n o t a t i o n f o r i t s i n i t i a l i z i n g c o n s t a n t

The s y n t a c t i c e l e m e n t s f o r b) and c) w i l l be c a l l e d i n d i c a t o r s E x a m p l e s

real a b I m p l e m e n t a t i o n s t a n d a r d n u m b e r of d i g i t s no i n i t i a l i z a t i o n

c o m p l e x (16) c d e P r e c i s i o n at l e a s t 16 d e c i m a l d i g i t s no i n i t i a l i z a t i o n

i n t e g e r f=7 g = - 3 I m p l e m e n t a t i o n s t a n d a r d n u m b e r of d i g i t s i n i t i a l i z a t i o n

AB21 p 9

constant real h = l 734 In the b l o c k c o n c e r n e d the i d e n t i f i e r h is u s e d to deno te the c o n s t a n t 1 734 I t m a y not a p p e a r on l e f t hand s i d e s

c h a r a c t e r (12) k p Twelve bit characters no initialization

s t r i n g (200 6) m M a x i m u m l e n g t h 200 c h a r a c t e r s of 6 b i t s e a c h No i n i t i a l i z a t i o n

b i t (40) n b l o l l M a x i m u m l e n g t h 40 b i t s i n i t i a l i z a t i o n a l l b i t s z e r o e x c e p t b i t s 1 2 and 4 f r o m the r i g h t

l a b e l L8 K22= ~ 24 I n i t i a l i z a t i o n of K22 The l a b e l cons t an t ~= 24 h a s to a p p e a r in a l a b e l c o n s t a n t de f in i t i on

~= 24

of tha t b l o c k o r an e m b r a c i n g b lock

It i s u n d e r s t o o d t h a t e a c h i m p l e m e n t o r w i l l s t a t e the v a l u e s he is a s s u m i n g i f an i n d i c a t o r i s m i s s i n g He wi l l a l s o s t a t e the u p p e r bounds f o r t h e s e q u a n t i t i e s In s o m e i m p l e m e n t a t i o n s t h e s e m a y be i d e n t i c a l wi th the de fau l t v a l u e s It i s a l s o u n d e r s t o o d tha t the i m p l e m e n t o r wi l l s t a t e c e r t a i n t h r e s h o l d v a l u e s to be c r u c i a l c o n c e r n i n g e f f i c i e n c y The i n d i c a t o r s f o r d ig i t n u m b e r s and c h a r a c t e r s i z e m a y only con t a in i n t e g e r

c o n s t a n t s

T h e s e b a s i c t y p e s a p p e a r in a r r a y and p r o c e d u r e d e c l a r a t i o n s in the u s u a l way p o s s i b l y wi th i n d i c a t o r s A r r a y d e c l a r a t i o n s s h o u l d at l e a s t a l low i n i t i a l i z a t i o n of a l l a r r a y c o m p o n e n t s wi th the s a m e v a l u e In c a s e t ha t w i th a m o r e g e n e r a l a p p r o a c h a n o t a t i o n f o r l i n e a r l i s t s shou ld be adop ted a m o r e f l e x i b l e i n i t i a l i z a t i o n s c h e m e would be p o s s i b l e

Examples

i n t e g e r (2o) a r r a y a 1 1 1 3 N M L o w e r and u p p e r bounds a r e e a c h in a l i n e a r l i s t (as wi th A L G O L 58) to a l low v a r i a b l e d i m e n s i o n a l i t y b y a r r a y i d e n t i f i e r s r e p r e s e n t i n g l i n e a r lists No initialization

character (6) array c iN = R Initialization of all components by the character R

AB21p I0

label array L 1122 = ~ i i ~ 12 ~ L21 ~ R22 R o w w i s e m a p p i n g i s a s s u m e d f o r i n i t i a l i z a t i o n

c o n s t a n t r e a l a r r a y r [ 25] = 1 37864 -2 -0 78 0

At compile time a correspondence is established for that block between the array components r [ i] and the constants listed to the right In the case of arrays this constant declaration yields more than the macro technique usually employed (Nevertheless the possibility to define simple macros should also exist in ALGOL X)

Simplifying the notation (Write A until B of the step-until element or A upto B

if the step is one)

In ALGOL 58 we had the convenient (but ambiguous) notation A(B)C for the step-until element In ALGOL 60 this notation still would have been ambiguous (an example is p(x)+N p being a formal real procedure parameter) and it is assumed that this will also hold in ALGOL X A great percentage of step-until elements in programs however has step one It is therefore suggested to allow one of the additional notations

A un t i l C or A u p t o C ( [ 5 ] p 84) f o r

A s t e p 1 un t i l C

Of course this does not imply leaving the for statement as it stands

The introduction of (Simple and safe means for optimizing pseudo-constants and repetitive statements easily separate a c o n s e q u e n c e of t h i s listing of input and output parameters

in procedures)

The notion of pseudoconstants or local constants has been discussed elsewhere eg see [4] The intention is to freeze the value of a variable over a certain period during computation primarily for efficiency reasons No assignment to this quantity is allowed during that period Our proposal starts with the observation that the importance of pseudoconstants is coupled with their appearance in statements of repetitive nature So let us define another repetitive clause different from the for clause the controlled variables of which has no relation to any of the declared variables of the program and which is assumed to be of type integer Let us call it the all clause The list elements of the for list except the while element are allowed within an all list The all clause

AB21 p i i

has the forii~

ltall clausegt = all ltidentifiergt = roll list gt do

The effect of

all V = A B step C until D do statementS

where A B C and D s tand fo r e x p r e s s i o n s is not defined if S does conta in exp l ic i t a s s i g n m e n t s to V or p rocedu re ca l l s with V as an ac tua l p a r a m e t e r of output na tu r e Exc lud ing th i s the ef fect is equ iva len t to the fol lowing ALGOL 60 p r o g r a m

begin p r o c e d u r e ST(V) value V i n t e g e r V s t a t e m e n t S

p r o c e d u r e ALL (A B C D St) value A B C D i n t e g e r A B C D p rocedu re St begin i n t e g e r V f o r V = A B C s t e P C u n t i l D d_ 2 St(V) end

ALL(A B C D ST end

To avoid the above men t ioned ca se s where the ef fec t of the a l l s t a t e m e n t is not def ined the c o m p i l e r has to check wi thin the s t a t e m e n t S

a) f o r exp l ic i t a s s i g n m e n t s to V and b) f o r p r o c e d u r e cal ls having V as ac tua l

p a r a m e t e r of output na tu re

F u r t h e r checks a re not n e c e s s a r y as lef t hand globals of p r o c e d u r e s a re e i t h e r not i den t i ca l with V o r t hey belong to ca t ego ry a)

Po in t b) is the i n t e r e s t i n g one The s y n t a c t i c s t r u c t u r e of the ALGOL 60 p r o c e d u r e s t a t e m e n t does not al low decid ing whe the r an ac tua l p a r a m e t e r is of input o r output na tu re o r both But the in t roduc t ion of the a l l s t a t e m e n t c r i e s f o r th is p os s ib i l i t y (There a re s e v e r a l o the r r e a s o n s too) On the o the r hand the c o m p i l e r can e a s i l y d e t e r m i n e the v a r i a b l e s which a r e a s s igned va lues exp l i c i t l y because they occu r to the lef t of the r i g h t m o s t co lon -equa l of the a s s i g n m e n t s t a t e m e n t s Wel l then le t us

AB21 p 12

l i s t the output p a r a m e t e r s of a p r o c e d u r e to the le f t of a c e r t a i n m a r k a l so In m a n y c a s e s the p r o c e d u r e s t a t e m e n t m a y be r e g a r d e d as a s o r t of g e n e r a l i z e d a s s i g n m e n t s t a t e m e n t s o i t s e e m s n a t u r a l to r e w r i t e the h e a d i n g of the A L G O L 6o p r o c e d u r e d e c l a r a t i o n

p r o c e d u r e ASSIGN (a b ) v a l u e b i n t e g e r a b a=b

in the following way

procedure (a)ASSIGN(b)

The analogy between the call

(b [i] ) ASSIGN(20)

and the assignment statement

b [i] = 2o

and the above mentioned benefits of this regrouping are so attractive that it seems NO rthwhile to adopt this line of notation The following forms of procedure calls may occur

( )P( ) ( ) P( ) ( ) P( )

A consequence of this concept is that parameters of input and output nature (transients) have to be listed on both sides We come back to this later on

Note t ha t a s i m p l e c o m p i l e r m a y p r o d u c e a m o r e e f f i c i e n t code f r o m

all nc=n do all i = 1 upton do a [i] = b [i nc]

than from all i = 1 upto n d_o a [i] = b [in]

This remark suggests a generalization of the all clause in the followiug direction Let AiA2 An be integer expressions or integer step-until elements and ai be identifiers then

a l l a l a2 an = A I A 2 An do

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 2: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 8

compiler is written for A constant of type character is denoted by including the single hardware-character by some sort of quotes If the hardware character has no representation on the medium used for the source program then

( ltunsigned in tege rgt )

i s to r e p r e s e n t the c h a r a c t e r [2] The i m p l e m e n t o r has to s p e c i f y the c o r r e s p o n d e n c e b e t w e e n i n t e g e r s and those h a r d w a r e c h a r a c t e r s E x a m p l e s

A vv _j vu

Iv I v ( 6 4 )

S t r i n g c o n s t a n t s shou ld be t r e a t e d a long the s a m e l i n e s The q u e s t i o n w h e t h e r c h a r a c t e r a n d ] o r s t r i n g t y p e s a r e a d v i s a b l e i s not dis c u s s e d h e r e

The s u p e r quote o p e r a t o r m e n t i o n e d in [3] shou ld a p p e a r as one of the b a s i c s y m b o l s of the l a n g u a g e A s e c o n d one has to be i n t r o - duced in c a s e a c h a r a c t e r deno ted by an i n t e g e r as above is a l lowed to a p p e a r in a s t r i n g c o n s t a n t

In c o m p a r i s o n wi th A L G O L 6o type d e c l a r a t i o n s shou ld be g e n e r a l i z e d in s u c h a w a y tha t t h e y a l low

a) i n i t i a l i z a t i o n b) a r e m a r k on the m i n i m u m n u m b e r of d e c i m a l d ig i t s to

be c a r r i e d wi th ( for a r i t h m e t i c t ypes only) c) a r e m a r k on the s i z e of s t o r a g e which wi l l be r e s e r v e d

f o r the v a r i a b l e c o n c e r n e d ( for c h a r a c t e r s t r i n g and b i t only)

d) a way to i n d i c a t e t h a t the v a r i a b l e i s u sed only as a n o t h e r d e n o t a t i o n f o r i t s i n i t i a l i z i n g c o n s t a n t

The s y n t a c t i c e l e m e n t s f o r b) and c) w i l l be c a l l e d i n d i c a t o r s E x a m p l e s

real a b I m p l e m e n t a t i o n s t a n d a r d n u m b e r of d i g i t s no i n i t i a l i z a t i o n

c o m p l e x (16) c d e P r e c i s i o n at l e a s t 16 d e c i m a l d i g i t s no i n i t i a l i z a t i o n

i n t e g e r f=7 g = - 3 I m p l e m e n t a t i o n s t a n d a r d n u m b e r of d i g i t s i n i t i a l i z a t i o n

AB21 p 9

constant real h = l 734 In the b l o c k c o n c e r n e d the i d e n t i f i e r h is u s e d to deno te the c o n s t a n t 1 734 I t m a y not a p p e a r on l e f t hand s i d e s

c h a r a c t e r (12) k p Twelve bit characters no initialization

s t r i n g (200 6) m M a x i m u m l e n g t h 200 c h a r a c t e r s of 6 b i t s e a c h No i n i t i a l i z a t i o n

b i t (40) n b l o l l M a x i m u m l e n g t h 40 b i t s i n i t i a l i z a t i o n a l l b i t s z e r o e x c e p t b i t s 1 2 and 4 f r o m the r i g h t

l a b e l L8 K22= ~ 24 I n i t i a l i z a t i o n of K22 The l a b e l cons t an t ~= 24 h a s to a p p e a r in a l a b e l c o n s t a n t de f in i t i on

~= 24

of tha t b l o c k o r an e m b r a c i n g b lock

It i s u n d e r s t o o d t h a t e a c h i m p l e m e n t o r w i l l s t a t e the v a l u e s he is a s s u m i n g i f an i n d i c a t o r i s m i s s i n g He wi l l a l s o s t a t e the u p p e r bounds f o r t h e s e q u a n t i t i e s In s o m e i m p l e m e n t a t i o n s t h e s e m a y be i d e n t i c a l wi th the de fau l t v a l u e s It i s a l s o u n d e r s t o o d tha t the i m p l e m e n t o r wi l l s t a t e c e r t a i n t h r e s h o l d v a l u e s to be c r u c i a l c o n c e r n i n g e f f i c i e n c y The i n d i c a t o r s f o r d ig i t n u m b e r s and c h a r a c t e r s i z e m a y only con t a in i n t e g e r

c o n s t a n t s

T h e s e b a s i c t y p e s a p p e a r in a r r a y and p r o c e d u r e d e c l a r a t i o n s in the u s u a l way p o s s i b l y wi th i n d i c a t o r s A r r a y d e c l a r a t i o n s s h o u l d at l e a s t a l low i n i t i a l i z a t i o n of a l l a r r a y c o m p o n e n t s wi th the s a m e v a l u e In c a s e t ha t w i th a m o r e g e n e r a l a p p r o a c h a n o t a t i o n f o r l i n e a r l i s t s shou ld be adop ted a m o r e f l e x i b l e i n i t i a l i z a t i o n s c h e m e would be p o s s i b l e

Examples

i n t e g e r (2o) a r r a y a 1 1 1 3 N M L o w e r and u p p e r bounds a r e e a c h in a l i n e a r l i s t (as wi th A L G O L 58) to a l low v a r i a b l e d i m e n s i o n a l i t y b y a r r a y i d e n t i f i e r s r e p r e s e n t i n g l i n e a r lists No initialization

character (6) array c iN = R Initialization of all components by the character R

AB21p I0

label array L 1122 = ~ i i ~ 12 ~ L21 ~ R22 R o w w i s e m a p p i n g i s a s s u m e d f o r i n i t i a l i z a t i o n

c o n s t a n t r e a l a r r a y r [ 25] = 1 37864 -2 -0 78 0

At compile time a correspondence is established for that block between the array components r [ i] and the constants listed to the right In the case of arrays this constant declaration yields more than the macro technique usually employed (Nevertheless the possibility to define simple macros should also exist in ALGOL X)

Simplifying the notation (Write A until B of the step-until element or A upto B

if the step is one)

In ALGOL 58 we had the convenient (but ambiguous) notation A(B)C for the step-until element In ALGOL 60 this notation still would have been ambiguous (an example is p(x)+N p being a formal real procedure parameter) and it is assumed that this will also hold in ALGOL X A great percentage of step-until elements in programs however has step one It is therefore suggested to allow one of the additional notations

A un t i l C or A u p t o C ( [ 5 ] p 84) f o r

A s t e p 1 un t i l C

Of course this does not imply leaving the for statement as it stands

The introduction of (Simple and safe means for optimizing pseudo-constants and repetitive statements easily separate a c o n s e q u e n c e of t h i s listing of input and output parameters

in procedures)

The notion of pseudoconstants or local constants has been discussed elsewhere eg see [4] The intention is to freeze the value of a variable over a certain period during computation primarily for efficiency reasons No assignment to this quantity is allowed during that period Our proposal starts with the observation that the importance of pseudoconstants is coupled with their appearance in statements of repetitive nature So let us define another repetitive clause different from the for clause the controlled variables of which has no relation to any of the declared variables of the program and which is assumed to be of type integer Let us call it the all clause The list elements of the for list except the while element are allowed within an all list The all clause

AB21 p i i

has the forii~

ltall clausegt = all ltidentifiergt = roll list gt do

The effect of

all V = A B step C until D do statementS

where A B C and D s tand fo r e x p r e s s i o n s is not defined if S does conta in exp l ic i t a s s i g n m e n t s to V or p rocedu re ca l l s with V as an ac tua l p a r a m e t e r of output na tu r e Exc lud ing th i s the ef fect is equ iva len t to the fol lowing ALGOL 60 p r o g r a m

begin p r o c e d u r e ST(V) value V i n t e g e r V s t a t e m e n t S

p r o c e d u r e ALL (A B C D St) value A B C D i n t e g e r A B C D p rocedu re St begin i n t e g e r V f o r V = A B C s t e P C u n t i l D d_ 2 St(V) end

ALL(A B C D ST end

To avoid the above men t ioned ca se s where the ef fec t of the a l l s t a t e m e n t is not def ined the c o m p i l e r has to check wi thin the s t a t e m e n t S

a) f o r exp l ic i t a s s i g n m e n t s to V and b) f o r p r o c e d u r e cal ls having V as ac tua l

p a r a m e t e r of output na tu re

F u r t h e r checks a re not n e c e s s a r y as lef t hand globals of p r o c e d u r e s a re e i t h e r not i den t i ca l with V o r t hey belong to ca t ego ry a)

Po in t b) is the i n t e r e s t i n g one The s y n t a c t i c s t r u c t u r e of the ALGOL 60 p r o c e d u r e s t a t e m e n t does not al low decid ing whe the r an ac tua l p a r a m e t e r is of input o r output na tu re o r both But the in t roduc t ion of the a l l s t a t e m e n t c r i e s f o r th is p os s ib i l i t y (There a re s e v e r a l o the r r e a s o n s too) On the o the r hand the c o m p i l e r can e a s i l y d e t e r m i n e the v a r i a b l e s which a r e a s s igned va lues exp l i c i t l y because they occu r to the lef t of the r i g h t m o s t co lon -equa l of the a s s i g n m e n t s t a t e m e n t s Wel l then le t us

AB21 p 12

l i s t the output p a r a m e t e r s of a p r o c e d u r e to the le f t of a c e r t a i n m a r k a l so In m a n y c a s e s the p r o c e d u r e s t a t e m e n t m a y be r e g a r d e d as a s o r t of g e n e r a l i z e d a s s i g n m e n t s t a t e m e n t s o i t s e e m s n a t u r a l to r e w r i t e the h e a d i n g of the A L G O L 6o p r o c e d u r e d e c l a r a t i o n

p r o c e d u r e ASSIGN (a b ) v a l u e b i n t e g e r a b a=b

in the following way

procedure (a)ASSIGN(b)

The analogy between the call

(b [i] ) ASSIGN(20)

and the assignment statement

b [i] = 2o

and the above mentioned benefits of this regrouping are so attractive that it seems NO rthwhile to adopt this line of notation The following forms of procedure calls may occur

( )P( ) ( ) P( ) ( ) P( )

A consequence of this concept is that parameters of input and output nature (transients) have to be listed on both sides We come back to this later on

Note t ha t a s i m p l e c o m p i l e r m a y p r o d u c e a m o r e e f f i c i e n t code f r o m

all nc=n do all i = 1 upton do a [i] = b [i nc]

than from all i = 1 upto n d_o a [i] = b [in]

This remark suggests a generalization of the all clause in the followiug direction Let AiA2 An be integer expressions or integer step-until elements and ai be identifiers then

a l l a l a2 an = A I A 2 An do

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 3: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 9

constant real h = l 734 In the b l o c k c o n c e r n e d the i d e n t i f i e r h is u s e d to deno te the c o n s t a n t 1 734 I t m a y not a p p e a r on l e f t hand s i d e s

c h a r a c t e r (12) k p Twelve bit characters no initialization

s t r i n g (200 6) m M a x i m u m l e n g t h 200 c h a r a c t e r s of 6 b i t s e a c h No i n i t i a l i z a t i o n

b i t (40) n b l o l l M a x i m u m l e n g t h 40 b i t s i n i t i a l i z a t i o n a l l b i t s z e r o e x c e p t b i t s 1 2 and 4 f r o m the r i g h t

l a b e l L8 K22= ~ 24 I n i t i a l i z a t i o n of K22 The l a b e l cons t an t ~= 24 h a s to a p p e a r in a l a b e l c o n s t a n t de f in i t i on

~= 24

of tha t b l o c k o r an e m b r a c i n g b lock

It i s u n d e r s t o o d t h a t e a c h i m p l e m e n t o r w i l l s t a t e the v a l u e s he is a s s u m i n g i f an i n d i c a t o r i s m i s s i n g He wi l l a l s o s t a t e the u p p e r bounds f o r t h e s e q u a n t i t i e s In s o m e i m p l e m e n t a t i o n s t h e s e m a y be i d e n t i c a l wi th the de fau l t v a l u e s It i s a l s o u n d e r s t o o d tha t the i m p l e m e n t o r wi l l s t a t e c e r t a i n t h r e s h o l d v a l u e s to be c r u c i a l c o n c e r n i n g e f f i c i e n c y The i n d i c a t o r s f o r d ig i t n u m b e r s and c h a r a c t e r s i z e m a y only con t a in i n t e g e r

c o n s t a n t s

T h e s e b a s i c t y p e s a p p e a r in a r r a y and p r o c e d u r e d e c l a r a t i o n s in the u s u a l way p o s s i b l y wi th i n d i c a t o r s A r r a y d e c l a r a t i o n s s h o u l d at l e a s t a l low i n i t i a l i z a t i o n of a l l a r r a y c o m p o n e n t s wi th the s a m e v a l u e In c a s e t ha t w i th a m o r e g e n e r a l a p p r o a c h a n o t a t i o n f o r l i n e a r l i s t s shou ld be adop ted a m o r e f l e x i b l e i n i t i a l i z a t i o n s c h e m e would be p o s s i b l e

Examples

i n t e g e r (2o) a r r a y a 1 1 1 3 N M L o w e r and u p p e r bounds a r e e a c h in a l i n e a r l i s t (as wi th A L G O L 58) to a l low v a r i a b l e d i m e n s i o n a l i t y b y a r r a y i d e n t i f i e r s r e p r e s e n t i n g l i n e a r lists No initialization

character (6) array c iN = R Initialization of all components by the character R

AB21p I0

label array L 1122 = ~ i i ~ 12 ~ L21 ~ R22 R o w w i s e m a p p i n g i s a s s u m e d f o r i n i t i a l i z a t i o n

c o n s t a n t r e a l a r r a y r [ 25] = 1 37864 -2 -0 78 0

At compile time a correspondence is established for that block between the array components r [ i] and the constants listed to the right In the case of arrays this constant declaration yields more than the macro technique usually employed (Nevertheless the possibility to define simple macros should also exist in ALGOL X)

Simplifying the notation (Write A until B of the step-until element or A upto B

if the step is one)

In ALGOL 58 we had the convenient (but ambiguous) notation A(B)C for the step-until element In ALGOL 60 this notation still would have been ambiguous (an example is p(x)+N p being a formal real procedure parameter) and it is assumed that this will also hold in ALGOL X A great percentage of step-until elements in programs however has step one It is therefore suggested to allow one of the additional notations

A un t i l C or A u p t o C ( [ 5 ] p 84) f o r

A s t e p 1 un t i l C

Of course this does not imply leaving the for statement as it stands

The introduction of (Simple and safe means for optimizing pseudo-constants and repetitive statements easily separate a c o n s e q u e n c e of t h i s listing of input and output parameters

in procedures)

The notion of pseudoconstants or local constants has been discussed elsewhere eg see [4] The intention is to freeze the value of a variable over a certain period during computation primarily for efficiency reasons No assignment to this quantity is allowed during that period Our proposal starts with the observation that the importance of pseudoconstants is coupled with their appearance in statements of repetitive nature So let us define another repetitive clause different from the for clause the controlled variables of which has no relation to any of the declared variables of the program and which is assumed to be of type integer Let us call it the all clause The list elements of the for list except the while element are allowed within an all list The all clause

AB21 p i i

has the forii~

ltall clausegt = all ltidentifiergt = roll list gt do

The effect of

all V = A B step C until D do statementS

where A B C and D s tand fo r e x p r e s s i o n s is not defined if S does conta in exp l ic i t a s s i g n m e n t s to V or p rocedu re ca l l s with V as an ac tua l p a r a m e t e r of output na tu r e Exc lud ing th i s the ef fect is equ iva len t to the fol lowing ALGOL 60 p r o g r a m

begin p r o c e d u r e ST(V) value V i n t e g e r V s t a t e m e n t S

p r o c e d u r e ALL (A B C D St) value A B C D i n t e g e r A B C D p rocedu re St begin i n t e g e r V f o r V = A B C s t e P C u n t i l D d_ 2 St(V) end

ALL(A B C D ST end

To avoid the above men t ioned ca se s where the ef fec t of the a l l s t a t e m e n t is not def ined the c o m p i l e r has to check wi thin the s t a t e m e n t S

a) f o r exp l ic i t a s s i g n m e n t s to V and b) f o r p r o c e d u r e cal ls having V as ac tua l

p a r a m e t e r of output na tu re

F u r t h e r checks a re not n e c e s s a r y as lef t hand globals of p r o c e d u r e s a re e i t h e r not i den t i ca l with V o r t hey belong to ca t ego ry a)

Po in t b) is the i n t e r e s t i n g one The s y n t a c t i c s t r u c t u r e of the ALGOL 60 p r o c e d u r e s t a t e m e n t does not al low decid ing whe the r an ac tua l p a r a m e t e r is of input o r output na tu re o r both But the in t roduc t ion of the a l l s t a t e m e n t c r i e s f o r th is p os s ib i l i t y (There a re s e v e r a l o the r r e a s o n s too) On the o the r hand the c o m p i l e r can e a s i l y d e t e r m i n e the v a r i a b l e s which a r e a s s igned va lues exp l i c i t l y because they occu r to the lef t of the r i g h t m o s t co lon -equa l of the a s s i g n m e n t s t a t e m e n t s Wel l then le t us

AB21 p 12

l i s t the output p a r a m e t e r s of a p r o c e d u r e to the le f t of a c e r t a i n m a r k a l so In m a n y c a s e s the p r o c e d u r e s t a t e m e n t m a y be r e g a r d e d as a s o r t of g e n e r a l i z e d a s s i g n m e n t s t a t e m e n t s o i t s e e m s n a t u r a l to r e w r i t e the h e a d i n g of the A L G O L 6o p r o c e d u r e d e c l a r a t i o n

p r o c e d u r e ASSIGN (a b ) v a l u e b i n t e g e r a b a=b

in the following way

procedure (a)ASSIGN(b)

The analogy between the call

(b [i] ) ASSIGN(20)

and the assignment statement

b [i] = 2o

and the above mentioned benefits of this regrouping are so attractive that it seems NO rthwhile to adopt this line of notation The following forms of procedure calls may occur

( )P( ) ( ) P( ) ( ) P( )

A consequence of this concept is that parameters of input and output nature (transients) have to be listed on both sides We come back to this later on

Note t ha t a s i m p l e c o m p i l e r m a y p r o d u c e a m o r e e f f i c i e n t code f r o m

all nc=n do all i = 1 upton do a [i] = b [i nc]

than from all i = 1 upto n d_o a [i] = b [in]

This remark suggests a generalization of the all clause in the followiug direction Let AiA2 An be integer expressions or integer step-until elements and ai be identifiers then

a l l a l a2 an = A I A 2 An do

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 4: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21p I0

label array L 1122 = ~ i i ~ 12 ~ L21 ~ R22 R o w w i s e m a p p i n g i s a s s u m e d f o r i n i t i a l i z a t i o n

c o n s t a n t r e a l a r r a y r [ 25] = 1 37864 -2 -0 78 0

At compile time a correspondence is established for that block between the array components r [ i] and the constants listed to the right In the case of arrays this constant declaration yields more than the macro technique usually employed (Nevertheless the possibility to define simple macros should also exist in ALGOL X)

Simplifying the notation (Write A until B of the step-until element or A upto B

if the step is one)

In ALGOL 58 we had the convenient (but ambiguous) notation A(B)C for the step-until element In ALGOL 60 this notation still would have been ambiguous (an example is p(x)+N p being a formal real procedure parameter) and it is assumed that this will also hold in ALGOL X A great percentage of step-until elements in programs however has step one It is therefore suggested to allow one of the additional notations

A un t i l C or A u p t o C ( [ 5 ] p 84) f o r

A s t e p 1 un t i l C

Of course this does not imply leaving the for statement as it stands

The introduction of (Simple and safe means for optimizing pseudo-constants and repetitive statements easily separate a c o n s e q u e n c e of t h i s listing of input and output parameters

in procedures)

The notion of pseudoconstants or local constants has been discussed elsewhere eg see [4] The intention is to freeze the value of a variable over a certain period during computation primarily for efficiency reasons No assignment to this quantity is allowed during that period Our proposal starts with the observation that the importance of pseudoconstants is coupled with their appearance in statements of repetitive nature So let us define another repetitive clause different from the for clause the controlled variables of which has no relation to any of the declared variables of the program and which is assumed to be of type integer Let us call it the all clause The list elements of the for list except the while element are allowed within an all list The all clause

AB21 p i i

has the forii~

ltall clausegt = all ltidentifiergt = roll list gt do

The effect of

all V = A B step C until D do statementS

where A B C and D s tand fo r e x p r e s s i o n s is not defined if S does conta in exp l ic i t a s s i g n m e n t s to V or p rocedu re ca l l s with V as an ac tua l p a r a m e t e r of output na tu r e Exc lud ing th i s the ef fect is equ iva len t to the fol lowing ALGOL 60 p r o g r a m

begin p r o c e d u r e ST(V) value V i n t e g e r V s t a t e m e n t S

p r o c e d u r e ALL (A B C D St) value A B C D i n t e g e r A B C D p rocedu re St begin i n t e g e r V f o r V = A B C s t e P C u n t i l D d_ 2 St(V) end

ALL(A B C D ST end

To avoid the above men t ioned ca se s where the ef fec t of the a l l s t a t e m e n t is not def ined the c o m p i l e r has to check wi thin the s t a t e m e n t S

a) f o r exp l ic i t a s s i g n m e n t s to V and b) f o r p r o c e d u r e cal ls having V as ac tua l

p a r a m e t e r of output na tu re

F u r t h e r checks a re not n e c e s s a r y as lef t hand globals of p r o c e d u r e s a re e i t h e r not i den t i ca l with V o r t hey belong to ca t ego ry a)

Po in t b) is the i n t e r e s t i n g one The s y n t a c t i c s t r u c t u r e of the ALGOL 60 p r o c e d u r e s t a t e m e n t does not al low decid ing whe the r an ac tua l p a r a m e t e r is of input o r output na tu re o r both But the in t roduc t ion of the a l l s t a t e m e n t c r i e s f o r th is p os s ib i l i t y (There a re s e v e r a l o the r r e a s o n s too) On the o the r hand the c o m p i l e r can e a s i l y d e t e r m i n e the v a r i a b l e s which a r e a s s igned va lues exp l i c i t l y because they occu r to the lef t of the r i g h t m o s t co lon -equa l of the a s s i g n m e n t s t a t e m e n t s Wel l then le t us

AB21 p 12

l i s t the output p a r a m e t e r s of a p r o c e d u r e to the le f t of a c e r t a i n m a r k a l so In m a n y c a s e s the p r o c e d u r e s t a t e m e n t m a y be r e g a r d e d as a s o r t of g e n e r a l i z e d a s s i g n m e n t s t a t e m e n t s o i t s e e m s n a t u r a l to r e w r i t e the h e a d i n g of the A L G O L 6o p r o c e d u r e d e c l a r a t i o n

p r o c e d u r e ASSIGN (a b ) v a l u e b i n t e g e r a b a=b

in the following way

procedure (a)ASSIGN(b)

The analogy between the call

(b [i] ) ASSIGN(20)

and the assignment statement

b [i] = 2o

and the above mentioned benefits of this regrouping are so attractive that it seems NO rthwhile to adopt this line of notation The following forms of procedure calls may occur

( )P( ) ( ) P( ) ( ) P( )

A consequence of this concept is that parameters of input and output nature (transients) have to be listed on both sides We come back to this later on

Note t ha t a s i m p l e c o m p i l e r m a y p r o d u c e a m o r e e f f i c i e n t code f r o m

all nc=n do all i = 1 upton do a [i] = b [i nc]

than from all i = 1 upto n d_o a [i] = b [in]

This remark suggests a generalization of the all clause in the followiug direction Let AiA2 An be integer expressions or integer step-until elements and ai be identifiers then

a l l a l a2 an = A I A 2 An do

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 5: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p i i

has the forii~

ltall clausegt = all ltidentifiergt = roll list gt do

The effect of

all V = A B step C until D do statementS

where A B C and D s tand fo r e x p r e s s i o n s is not defined if S does conta in exp l ic i t a s s i g n m e n t s to V or p rocedu re ca l l s with V as an ac tua l p a r a m e t e r of output na tu r e Exc lud ing th i s the ef fect is equ iva len t to the fol lowing ALGOL 60 p r o g r a m

begin p r o c e d u r e ST(V) value V i n t e g e r V s t a t e m e n t S

p r o c e d u r e ALL (A B C D St) value A B C D i n t e g e r A B C D p rocedu re St begin i n t e g e r V f o r V = A B C s t e P C u n t i l D d_ 2 St(V) end

ALL(A B C D ST end

To avoid the above men t ioned ca se s where the ef fec t of the a l l s t a t e m e n t is not def ined the c o m p i l e r has to check wi thin the s t a t e m e n t S

a) f o r exp l ic i t a s s i g n m e n t s to V and b) f o r p r o c e d u r e cal ls having V as ac tua l

p a r a m e t e r of output na tu re

F u r t h e r checks a re not n e c e s s a r y as lef t hand globals of p r o c e d u r e s a re e i t h e r not i den t i ca l with V o r t hey belong to ca t ego ry a)

Po in t b) is the i n t e r e s t i n g one The s y n t a c t i c s t r u c t u r e of the ALGOL 60 p r o c e d u r e s t a t e m e n t does not al low decid ing whe the r an ac tua l p a r a m e t e r is of input o r output na tu re o r both But the in t roduc t ion of the a l l s t a t e m e n t c r i e s f o r th is p os s ib i l i t y (There a re s e v e r a l o the r r e a s o n s too) On the o the r hand the c o m p i l e r can e a s i l y d e t e r m i n e the v a r i a b l e s which a r e a s s igned va lues exp l i c i t l y because they occu r to the lef t of the r i g h t m o s t co lon -equa l of the a s s i g n m e n t s t a t e m e n t s Wel l then le t us

AB21 p 12

l i s t the output p a r a m e t e r s of a p r o c e d u r e to the le f t of a c e r t a i n m a r k a l so In m a n y c a s e s the p r o c e d u r e s t a t e m e n t m a y be r e g a r d e d as a s o r t of g e n e r a l i z e d a s s i g n m e n t s t a t e m e n t s o i t s e e m s n a t u r a l to r e w r i t e the h e a d i n g of the A L G O L 6o p r o c e d u r e d e c l a r a t i o n

p r o c e d u r e ASSIGN (a b ) v a l u e b i n t e g e r a b a=b

in the following way

procedure (a)ASSIGN(b)

The analogy between the call

(b [i] ) ASSIGN(20)

and the assignment statement

b [i] = 2o

and the above mentioned benefits of this regrouping are so attractive that it seems NO rthwhile to adopt this line of notation The following forms of procedure calls may occur

( )P( ) ( ) P( ) ( ) P( )

A consequence of this concept is that parameters of input and output nature (transients) have to be listed on both sides We come back to this later on

Note t ha t a s i m p l e c o m p i l e r m a y p r o d u c e a m o r e e f f i c i e n t code f r o m

all nc=n do all i = 1 upton do a [i] = b [i nc]

than from all i = 1 upto n d_o a [i] = b [in]

This remark suggests a generalization of the all clause in the followiug direction Let AiA2 An be integer expressions or integer step-until elements and ai be identifiers then

a l l a l a2 an = A I A 2 An do

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 6: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 12

l i s t the output p a r a m e t e r s of a p r o c e d u r e to the le f t of a c e r t a i n m a r k a l so In m a n y c a s e s the p r o c e d u r e s t a t e m e n t m a y be r e g a r d e d as a s o r t of g e n e r a l i z e d a s s i g n m e n t s t a t e m e n t s o i t s e e m s n a t u r a l to r e w r i t e the h e a d i n g of the A L G O L 6o p r o c e d u r e d e c l a r a t i o n

p r o c e d u r e ASSIGN (a b ) v a l u e b i n t e g e r a b a=b

in the following way

procedure (a)ASSIGN(b)

The analogy between the call

(b [i] ) ASSIGN(20)

and the assignment statement

b [i] = 2o

and the above mentioned benefits of this regrouping are so attractive that it seems NO rthwhile to adopt this line of notation The following forms of procedure calls may occur

( )P( ) ( ) P( ) ( ) P( )

A consequence of this concept is that parameters of input and output nature (transients) have to be listed on both sides We come back to this later on

Note t ha t a s i m p l e c o m p i l e r m a y p r o d u c e a m o r e e f f i c i e n t code f r o m

all nc=n do all i = 1 upton do a [i] = b [i nc]

than from all i = 1 upto n d_o a [i] = b [in]

This remark suggests a generalization of the all clause in the followiug direction Let AiA2 An be integer expressions or integer step-until elements and ai be identifiers then

a l l a l a2 an = A I A 2 An do

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 7: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 13

all al = A1 do all a2 = A2 do

all an = An do

Thus we can w r i t e f o r the above e x a m p l e

a__~ nc i = n 1 upto n d_o a [ i ] =b [ i nc ]

It is u n d e r s t o o d tha t the n u m b e r s of e n t r i e s in the i d e n t i f i e r l i s t and in the a l l l i s t have to be e q u a l if the i d e n t i f i e r l i s t has m o r e than one e n t r y S o m e t i m e s i t m a y be d e s i r a b l e to d e c l a r e a v a r i a b l e to be a p s e u d o c o n s t a n t which is not of type i n t e g e r It is f e l t h o w e v e r tha t p a c k i n g th i s in to the a l l c l a u s e too would m e a n o v e r l o a d i n g th i s m e chan i s m

The n a t u r e of f o r m a l p a r a m e t e r s (The so called reference variables behave essentially like ALGOL 60 name parameters proposal to use reference variables in ALGOL X)

The f o r m a l p a r a m e t e r s of A L G O L 60 a r e a v e r y p o w e r f u l too l and t h e r e f o r e l e t us i n v e s t i g a t e why th i s is so and how we can take advan tage of t h e i r m e c h a n i s m f o r o t h e r p u r p o s e s Le t A and B be r e a l d e c l a r e d v a r i a b l e s and X and Y r e a l n a m e s p e c i f i e d f o r m a l p a r a m e t e r s in the s e n s e of A L G O L 60 The d i f f e r e n c e b e t w e e n the a s s i g n m e n t s t a t e m e n t s

A =B and A =X

is that in the s e c o n d c a s e X f i r s t is r e p l a c e d by i t s a c tua l p a r a m e t e r b e f o r e in bo th c a s e s the u s u a l e v a l u a t i o n and a s s i g n m e n t t ake p l a c e S i m i l a r l y ff X o c c u r s on the l e f t hand s i d e i t i s r e p l a c e d by i t s a c t u a l p a r a m e t e r p r i o r to a s s i g n m e n t Th is r e p l a c e m e n t m a y f o r m a l l y be d e s c r i b e d by m e a n s of s o m e r e p l a c e m e n t o p e r a t o r w h e r e a s the u s u a l e v a l u a t i o n m a y be d e s c r i b e d by a n o t h e r o p e r a t o r In [ 5 ] i t was s h o w n in p r a c t i c e tha t both o p e r a t o r s m a y be m a d e i d e n t i c a l p r o v i d e d tha t a s u i t a b l e d e f i n i t i o n is u s e d L e t us deno te t h i s o p e r a t o r by v T h e n we can d e s c r i b e A L G O L 60 a s s i g n m e n t s t a t e m e n t s by a m o r e e l e m e n t a r y no ta t ion

a) A =B A lt _v B b) A=X Alt _v _v X

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 8: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

A~21 p 14

c) X=A v X lt v A d) X=Y vXlt = v v Y

The striking thing is that we cannot assign to the formal parameter itself We can only assign to its value ALGOL 60 is hiding this direct assignment behind the actual-formal correspondence mechanism And what is assigned Example c) shows clearly that it has to be the reference to an actual parameter This means that X is a variable which may take on a reference to another variable as its value So we can conclude that a subset of the ALGOL 60 formal parameters consists of variables of type reference These variables have the extra property that every occurrence of them within the procedure body implies automatically one evaluation step irrespective of the syntactic situation they appear in Trying to assign directly to such a reference variable means in accordance with a) through d) that we must introduce ira t9 the language the inverse operator of v Let us call it the reference operator and denote it by ref We are going to apply now this operator on both sides of the assignment statement of example c) and obtain

e) r e f X = r e f A X lt - - - - A

According to the right half of e) this means that the reference to A is assigned to X Applying ref to example d) we obtain

f) ref X = ref Y Xlt--v Y

This means that the variable reference stored in Y is also stored inX Iterated application of the reference operator is not allowed

Our proposal is to use reference variables in ALGOL X with properties illustrated by examples a) through f) They are so attractive because they behave like a part of the formal parameters of ALGOL 6o The specifications of name parameters in ALGOL 6o may be regarded simply as declarations of reference variables and the formal parameter list says in which order they are to be initialized upon call The discussion on procedure parameters will be resumed in section 6

Types once more (Declaration of reference variables such that static type checking is possible rules to prevent referencing of quantities outside their scope which can be checked at compile time)

The principles of static type checking set up for ALGOL X require an elaborate declaration of reference variables Having already introduced 8 basic types in section 1 and their combinations with array

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 9: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

A~ZI p ib

and p r o c e d u r e we n e e d f o r b r e v i t y the c o n s t r u c t

lt q u a l i t y gt= ltbas ic type gt I array [ p r o c e d u r e I ltbas i c type bull a r r a y 1lt b a s i c type gt p r o c e d u r e

Up to now e a c h v a r i a b l e is a s s o c i a t e d wi th e x a c t l y one of t h e s e q u a l i t i e s A l l of t h e m shou ld be capab le of b e i n g r e f e r e n c e d This m e a n s i n t r o d u c i n g the d e c l a r a t o r s

lt qua l i t y ~ r e f e r e n c e and lt qua l i ty bull r e f e r e n c e a r r a y

M o r e o v e r i t m i g h t be of i n t e r e s t to have

~quality gt r e f e r e n c e p r o c e d u r e

f o r the c o m p u t a t i o n of r e f e r e n c e s Aga in ff s u c h p r o d e c u r e n a m e s a r e to be r e f e r e n c e d t h e n we m u s t have

lt qua l i t y bull r e f e r e n c e p r o c e d u r e r e f e r e n c e and lt qua l i t y gt r e f e r e n c e p r o c e d u r e r e f e r e n c e a r r a y

E x a m p l e s

c o m p l e x (20) r e f e r e n c e r c o n s t a n t r e a l (12) p r o c e d u r e r e f e r e n c e a r r a y f [ l 4 ] = f l f 2 ~ f 3 f 4

B a s i c s y n t a c t i c c o n s t i t u e n t s of r e f e r e n c e e x p r e s s i o n s a r e

a) c o n s t r u c t s of the f o r m r e f lt v a r i a b l e bull b) r e f e r e n c e p r o c e d u r e ca l l s c) c o n s t r u c t s of the f o r n i lt e x p r e s s i o n bull

- ( s e e s e c t i o n 6)

By means of selective clauses (conditional case) reference expressions are built up from these basic constituents Left hand reference expressions have only the basic constituent a) where the variable has to be a reference variable (Note that reference variables can never refer to reference variables because iterated application of the ref operator is not permitted see section 4) Reference assignment statements have the general form

lt 1 h r e f e x p r gt = lt 1 h r e f e x p r gt = ~rr~- I = lt r e f e x p r bull

An u n r e s t r i c t e d use of th i s s t a t e m e n t would be c a t a s t r o p h i c In o r d e r

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 10: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 16

to describe restrictions similar to those of [I ] we call a block in which a quantity is declared the block belonging to this quantity The block belonging to a construct of the form a) is the block belonging to the variable concerned in case b) it is the block belonging to the procedure identifier in case c) it is the smallest block among the blocks belonging to the constituents of the expressions concerned We call the smallest block among the blocks belonging to the basic constituents of a reference expression the minimum block of that reference expression Analogously the maximum block is defined A reference statement is undefined

if the greatest block among the maximum blocks of the left hand reference expressions is greater than the minimum block of the right hand reference expression

if diffe rent qualities appear

The definition of the block belonging to a reference procedure makes it necessary to insure that a reference procedure always produces a reference to a variable declared in a block which is not smaller than the block belonging to the procedure identifier A reference procedure is undefined

if the mkimum block of the result expression is smaller than the block belonging to the procedure identifier

if r e s u l t expression and p r o c e d u r e identifier have diffe r e n t q u a l i t i e s

(Note that the blocks belonging toformal parameters of a procedure are smaller than the block belonging to the procedure identifierl)

Conditions 1 through 4 may easily be checked at compile time

F o r r e a s o n s of a d i f f e r e n t n a t u r e the r e f e r e n c i n g of c o n t r o l l e d v a r i a b l e s of a l l c l a u s e s w i l l not be a l l o w e d R e f e r e n c i n g of t r e e - e l e m e n t s has s t i l l to be s t u d i e d

Closing this section it may be noted that posing the question of the advisability of introducing reference variables in ALGOL X is mis- leading in a certain sense because they are in anyway namely as formal paramete rs

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 11: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 17

D i s c u s s i o n of p r o c e d u r e s ( The old spec i f i ca t ions a r e now d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s r e f e r e n c e a r r a y s f o r s equences of p a r a m e t e r s with iden t ica l qual i ty a r e a l lowed cal l by value and cal l by r e f e r e n c e old J e n s e n device posi t ions a r e now p r o c e d u r e p a r a m e t e r s Sepa ra t e l i s t ing of input and output p a r a m e t e r s )

Le t us s t a r t with a t r a n s c r i p t i o n of two example s f r o m the ALGOL 60 r e p o r t us ing the nota t ion developed so f a r (note that we will s imp l i fy this nota t ion in this sec t ion)

a) p r o c e d u r e (y p) INNERPRODUCT(a b k) r e a l r e f e r e n c e y i n t e g e r r e f e r e n c e p r e a l p r o c e d u r e r e f e r e n c e a b i n t e g e r k begin r e a l s

a_H i = 1 upto k do begin p=i s=s+axb end

end inne r p r o d u c t

b) p r o c e d u r e (a)TRANSPOSE (a n) a r r a y r e f e r e n c e a a i n t e g e r n begin r e a l w

a ~ i k = 1 u p t o n l+ i upto n g d o

begin w = a [ i k ]

a [ i k ] = a [ k i ] a [ k i ] = w

end

end t r a n s p o s e

The c o r r e s p o n d i n g cal ls would r ead

a l ) ( re f Y r e f P ) I N N E R P R O D U C T ( A[ t P u ] B [ P ] lo) b l ) ( r e f W)TRANSPOSE( re f W v+l)

Some of the changes m a d e in c o m p a r i s o n with the ALGOL 60 nota t ion a r e

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 12: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 18

The A L G O L 60 s p e c i f i c a t i o n s a p p e a r h e r e as d e c l a r a t i o n s n a m e l y as d e c l a r a t i o n s of r e f e r e n c e v a r i a b l e s f o r n o n - v a l u e p a r a m e t e r s and as the u s u a l d e c l a r a t i o n s f o r v a l u e p a r a m e t e r s

The p o s i t i o n s c o r r e s p o n d i n g to A L G O L 60 n a m e p a r a m e t e r s the a c t u a l s of w h i c h a r e e x p e c t e d to m a k e use of the fu l l A L G O L 6o n a m e ca l l p o s s i b i l i t i e s a r e d e c l a r e d as p r o c e d u r e r e f e r e n c e s E x a c t l y in t h e s e r e l a t i v e l y r a r e c a s e s the c o m p i l e r ha s to p r o v i d e f o r the who le n a m e m e c h a n i s m of A L G O L 60 A l l the so c a l l e d s i m p l e n a m e p o s i t i o n s m a y be t r e a t e d m o r e e f f i c i e n t l y

T r a n s i e n t s a p p e a r on bo th s i d e s The f i r s t o c c u r r e n c e of the c o r r e s p o n d i n g i d e n t i f i e r in a d e c l a r a t i o n r e f e r s to the l e f t hand p a r a m e t e r the s e c o n d one to the r i g h t hand p a r a m e t e r

4 On the ca l l s i d e we have a n o t a t i o n f o r the p a r a m e t e r s e s s e n t i a l l y the s a m e as in [5]

c a l l b y v a l u e Expression without additional marks

ca l l b y r e f e r e n c e R e f e r e n c e e x p r e s s i o n

c a l l by p r o c e d u r e An abbreviated notation for a reference to a procedure by means of quotes On principle this is not a third type of call It is a special case of call by reference

The m e c h a n i s m of the f o r m a l a c t u a l c o r r e s p o n d e n c e can be d e s c r i b e d now in the l a n g u a g e F o r the above e x a m p l e s we have

a2) r e f y= r e f Y r e f p= r e f P r e f a= A[ t P u ] r e f b = B [ P ]

k= l o

b2) ref a= ref W F o r a t r a n s i e n t x two v a r i a b l e s a r e u s e d ref a = ref W n a m e l y x and x If x o c c u r s in a l e f t -

n= v+l hand p o s i t i o n t h e n x is u s e d o t h e r w i s e x

A d o p t i n g the c o n c e p t as i t s t a n d s at the m o m e n t an a r r a y i d e n t i f i e r c a l l e d b y v a l u e h a s a p a r a m e t e r d e c l a r a t i o n w h i c h is an a r r a y d e c l a r a t i o n the bounds of w h i c h have to a p p e a r as f u n c t i o n s of o t h e r p a r a m e t e r s o r g l o b a l s H e r e i t i s v e r y c o n v e n i e n t to have the a r r a y a s s i g n m e n t a=b f o r a r r a y s wi th m a t c h i n g b o u n d s It s h o u l d be c o n t a i n e d in A L G O L X

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 13: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 19

The concep t d e s c r i b e d l ends i t s e l f e a s i l y to a c h i e v i n g c a l l s wi th v a r i a b l e n u m b e r s of n o n - v a l u e p a r a m e t e r s of the s a m e qua l i t y

E x a m p l e ( for l a t e r r e f e r e n c e m a r k e d by c)

c) procedure ( a ) T R A N S P O R T ( n b) real n real reference array ab [ ln] all i= lupto n d_o a[ i] =b [i]

c l ) ( r e f a [ i ] r e f d ) T R A N S P O R T ( 2 r e f s r e f c [ 7 ] )

bullT h i s i s c l u m s y and s h o w s t h a t i t i s d e s i r a b l e

1) to get r id of the r e f s y m b o l on the l e f t and

2) to t ake c a r e of v a r i a b l e p a r a m e t e r n u m b e r s f o r va lue p a r a m e t e r s a l s o s o t ha t in s u c h c a s e s r e f e r e n c e s m a y be r e p l a c e d b y v a l u e s

P o i n t 1) can be s e t t l e d by conven t ion If a l e f t hand p o s i t i o n i s not a r e f e r e n c e t h e n the r e f o p e r a t o r i s i m p l i e d (Note t h a t a l e f t hand p o s i t i o n m a y be occup ied b y a q u a l i t y r e f e r e n c e p r o c e d u r e )

P o i n t 2) can be s e t t l e d b y d e s c r i b i n g the va lue c a l l in a n o t h e r way L e t r e f e r e n c e v a r i a b l e d e c l a r a t i o n s c o r r e s p o n d to a l l p r o c e d u r e p a r a m e t e r s At c a l l t i m e the va lue of a va lue p a r a m e t e r i s a s s i g n e d to a l o c a l v a r i a b l e of the s a m e q u a l i t y and the r e f e r e n c e v a r i a b l e i s a s s i g n e d the r e f e r e n c e to t h a t l o c a l v a r i a b l e T h i s h a s the e x t r a a d v a n t a g e t h a t on the c a l l s i de t h e r e i s f r e e d o m f o r s o m e p a r a m e t e r c l a s s e s to be ca l l e d b y va lue o r b y r e f e r e n c e F o r i n s t a n c e the a s s i g n m e n t k = 10 in e x a m p l e a2) would be r e p l a c e d b y

l o c v a r = l o r e f k = re f l o c v a r

H a v i n g r e f e r e n c e v a r i a b l e s f o r a l l p r o c e d u r e p a r a m e t e r s a l l ows the s u p p r e s s i o n of the d e l i m i t e r r e f e r e n c e f o r a l l d e c l a r a t o r s in the h e a d i n g f o r which i t i s the t e r m i n a t i n g d e c l a r a t o r

Now we can r e w r i t e the t h r e e e x a m p l e s of t h i s s e c t i o n in the f i n a l n o t a t i o n

a3) p r o c e d u r e (y p ) I N N E R P R O D U C T ( a b k) r e a l y i n t e g e r p k

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 14: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 20

r e a l procedure a b begLn r e a l s

a l l i = 1 upto k do begin p= i s = s+axb end end i n n e r p r o d u c t

b3) (de l e t e the d e l i m i t e r r e f e r e n c e in e x a m p l e b))

c3) identical with c))

a4) (YP)INNERPRODUCT( A [tPu] B [P] I0)

b4) ~W)TRANSPOSE ( re f Wv+l )

c4) (a [ i ] d ) T R A N S P O R T ( 2 s c [7] )

F o r c l a r i t y l e t us l i s t the p r o p o s e d changes in c o m p a r i s o n wi th A L G O L 6o C h a n g e s on the p r o c e d u r e d e c l a r a t i o n s i d e

1) To e a c h p a r a m e t e r c o r r e s p o n d s the d e c l a r a t i o n of a r e f e r e n c e v a r i a b l e The d e l i m i t e r r e f e r e n c e m a y be o m i t t e d if i t is the r i gh t te rn-dnat ing d e l i m i t e r of a de c l a r a t o r

2) Inputs a r e l i s t e d to the le f t of the p r o c e d u r e i d e n t i f i e r outputs to the r i g h t of i t T r a n s i e n t s a p p e a r on bo th s i d e s

3) The f i r s t a p p e a r a n c e of a t r a n s i e n t in the s e q u e n c e of d e c l a r a t i o n s r e f e r s to the output ~p a r a m e t e r the s e c o n d one to the input p a r a m e t e r

4 ) T h e r e is no va lue p a r t

5) J e n s e n p a r a m e t e r s have to be d e c l a r e d as n o r m a l p r o c e d u r e pa r a m e t e r s

6) S e q u e n c e s of p a r a m e t e r s wi th the s a m e qua l i t y m a y be a b b r e v i a t e d by a bull qua l i tygt r e f e r e n c e a r r a y d e c l a r a t i o n the bounds of wh ich m a y be func t ions of p a r a m e t e r s which have to be d e c l a r e d p r i o r to t h e i r o c c u r r e n c e in tha t d e c l a r a t i o n If s u c h an a r r a y of r e f e r e n c e s is not one- d i m e n s i o n a l t h e n r o w w i s e m a p p i n g of the e l e m e n t s is a s s u m e d

C h a n g e s on the p r o c e d u r e ca l l s i de

7 ) R e p e a t poin t 2 of th i s e n u m e r a t i o n

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 15: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 21

8) Al l output p o s i t i o n s have to be occup ied b y r e f e r e n c e e x p r e s s i o n s If s u c h a p o s i t i o n does not m e e t t h i s cond i t ion and i t i s a v a r i a b l e only t h e n the r e f e r e n c e o p e r a t o r i s i m p l i e d

9) An input p o s i t i o n m a y be occup ied e i t h e r by a r e f e r e n c e e x p r e s s i o n or b y a n o t h e r e x p r e s s i o n The l a t t e r p o s i t i o n s a r e s a i d to be c a l l e d b y v a l u e

i0) The e x p r e s s i o n s of a l l p o s i t i o n s (output and input) a r e e v a l u a t e d at c a l l t i m e f r o m le f t to r i gh t F o r e a c h p o s i t i o n the r e s u l t i s e i t h e r a r e f e r e n c e o r a n o t h e r v a l u e In the l a t t e r c a s e a new v a r i a b l e of the s a m e q u a l i t y as the va lue i s c r e a t e d and is a s s i g n e d t h i s v a l u e The r e f e r e n c e to t h i s v a r i a b l e i s the r e f e r e n c e c o r r e s p o n d i n g to t ha t p o s i t i o n The r e f e r e n c e s of a l l p o s i t i o n s a r e handed o v e r to the body f o r a c c e p t a b i l i t y t e s t i n g and i n i t i a l i z a t i o n of the c o r r e s p o n d i n g r e f e r e n c e v a r i a b l e s

II) The c o n s t r u c t ~ e x p r e s s i o n bull i s a n o t h e r no t a t i on f o r a r e f e r e n c e to a p r o c e d u r e n a m e l y to the p r o c e d u r e which has no p a r a m e t e r s and the body of wh ich c o n s i s t s of th i s e x p r e s s i o n If t h i s p r o c e d u r e had the p r o c e d u r e i d e n t i f i e r A the above c o n s t r u c t would be e q u i v a l e n t to re f A

A c k n o w l e d g m e n t s

The i d e a s d e v e l o p e d h e r e a r e in p a r t r e s u l t s of d i s c u s s i o n s b e t w e e n F L B a u e r K S a m e l s o n and the a u t h o r None of the d e b a t e r s h o w e v e r i s s a t i s f i e d b y e v e r y d e t a i l p r e s e n t e d

8 Refe r e n ce s

E W D i j k s t r a i n t e r n a l c o n t r i b u t i o n to WG 2 1 P r i n c e t o n 1965

[21 J C R e y n o l d s C O G E N T P r o g r a m m i n g M a n u a l A r g o n n e N a t i o n a l L a b o r a t o r y A N L - 7 0 2 2 M a r c h 65

[31 B R a n d e l l AB 1 8 3 1 1

E W Dijkstra P r o c of the I F I P CONGRESS 65 Vol l p 216 W a s h i n g t o n L o n d o n

NWirth and HWeber EULER a generalization of ALGOL and its forn~al definition T e c h R e p o r t CS 20 A p r i l 27 1965 S t a n f o r d U n i v e r s i t y

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965

Page 16: AB21 p. 7 AB21. S WORKING PAPERS AB21. S. 1 Some proposals ... · As in ALGOL 60 types are associated with variables. Operators may be defined to operate on more than one type class,

AB21 p 22

K o m m i s s i o n f u e r e l e k t r o n i s c h e s R e c h n e n de r Baye r i s t h e n A k a d e m i e de r Wis s ens cha f t en R i c h a r d W a g n e r s t r 18 8 M u n c h e n 2

G e r m a n y Augus t 1965


Recommended