ten mini-languages: a study of topical issues in programming languages

Upload: fanzefirl

Post on 01-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    1/32

    T e n M i n i - L a n g u a g e s :

    A S t u d y o f T o p i c a l I s s u e s in P P o g P a m m i n g L a n g u a g e s

    HENRY F. LEDGARD*

    Computer Science, The John s H op kins University, Baltimore, M aryla nd

    The proliferation of programming languages has raised many issues of language

    design, definition, and implementation. This paper presents a series of ten

    mini-languages, each of which exposes salient features found in existing

    programming languages. The value of the mini-languages lies in their brevity of

    description and the isolation of important linguistic features: in particular, the

    notions of assignment, transfer of control, functions, parameter passing, type

    checking, data structures, string manipulation, and input/output. The

    mini-languages may serve a variety of uses: notably, as a pedagogical tool for

    teaching programming languages, as a subject of study for the design of

    programming languages, and as a set of test eases for methods of language

    implementation or formal definition.

    Key words and phrases : curriculum for computer science, language design,

    compiler design, formal definition, syntax, semantics, assignment, transfer of

    control, functions, passing of parameters, type checking, string manipulation,

    data structures, input/output

    CR calegories: 1.3, 1.52, 4.10, 4.20, 4.22, 4.9

    GENERALCONSIDERATIONS

    Since the birth of I¢ORTRAN, the notion of

    higher-level programming languages has led

    to a proliferation of special-and general-

    purpose programming languages. It seems

    wise, at this juncture, to examine critical

    issues raised by the myriad of languages and

    to try to isolate certain important features

    that seem common to many programming

    languages. In this endeavor, we hav.e pre-

    pared ten mini-languages, each presenting

    in capsule form one or two features taken

    from existing programming languages. (The

    reader may find the work of Strachey [16]

    useful as a companion to this paper, as he

    considers many issues related to those pre-

    sented here.)

    The issues treated in this paper are sum-

    marized in Table I. Each mini-language is a

    * The work reported herein was performed in

    large part at the Programming Research Group,

    Computing Laboratory, Oxford University, Ox-

    ford, England.

    complete (although restricted language in

    itself, and each is described only informally.

    A modest appeal is made to the reader's

    knowledge of constructs in existing pro-

    gramming languages. None of the mini-

    languages are exact subsets of existing

    languages, although much of the notation

    and semantic material resembles portions of

    existing languages. Many important fen-

    tures of existing languages are omitted.

    These features include parallel computation,

    interrupts and events in real-time, file and

    storage management, and simulation.

    The format for presenting each mini-

    language is as follows:

    1) a brief introduction to some topic in

    programming languages;

    2) a description in English of a mini-

    language covering the topic;

    3) several example programs in the mini-

    language; and

    4) a discussion of the mini-language and

    Computing Surveys, Vol. 3, No. 3, September 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    2/32

    1 1 6 ° H en r y . L edgar d

    C O N T E N T S

    General Considerations 11~ 118

    Mini-Language 1 Simple Assignment, Transfer of

    Control, and Block Structure 118-119

    Description of Language Elements

    Piogram Execution

    Discussion

    Mini-Language 2: Generalized Assignment and the

    Notion of Locations 119-121

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 3: Generalized Transier of Control

    121-123

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 4: Functions 123-126

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 5: Passing of Parameters 126-128

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 6: Static Type Checking 128 132

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 7: Dynamic Type Checking 132-134

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 8: Structured Data 134-139

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 9: String Manipulation 139 142

    Description of Language Elements

    Program Execution

    Discussion

    Mini-Language 10: Input/Output 142-146

    Description of Language Elements

    Program Execution

    Discussion

    Acknowledgments 146

    References 146

    Copy right © 1971, Associat ion for Compu ting

    Machinery, Inc. General permission to republish,

    but not for profit , all or part of this material is

    granted, provided that reference is made to this

    publication, to its date of issue, and to the fact

    that reprint ing privi leges were granted by permis-

    sion of the Associat ion for Computing Machinery.

    i t s r e l a t i o n t o i s s u e s i n c u r r e n t p r o g ra m -

    m i n g l a n g u a g e s .

    T h e r e a p p e a r t o b e a t l e a s t f o u r m aj or

    a r e a s in w h i c h t h e m i n i - l a n g u a g e s m i g ht

    p r o v e u s e f u l :

    1 ) a s a p e d a g o g i c a l t o o l f o r t e a c h i n g p r o-

    g r a m m i n g l a n g u a g e s;

    2 ) a s a s u b j e c t o f s t u d y f o r l a n g u a g e d e-

    s i g n ;

    3 ) a s a s e t o f t e s t c a s e s f o r p r o p o s e d m e t h -

    o d s o f l a n g u a g e i m p l e m e n t a t i o n ; a n d

    4 ) a s a s e t o f t e s t c a s e s f o r p r o p o s e d m e t h -

    o d s o f f o r m a l d e f i n i t i o n .

    I n t e a c h i n g p r o g r a m m i n g l a n g u a g e s, o ne

    i m m e d i a t e p r o b l e m i s th a t m o s t l a ng u ag es

    a r e s o c o m p l e x t h a t a n y a t t e m p t t o is ola te

    t h e i r i m p o r t a n t f e a t u r e s r e q u i r e s a g o o d

    d e a l o f s t u d y . T h e r e i s c l e a r l y a n e e d fo r

    s m a l l , d i g e s t i b l e e x a m p l e s t o i ll u m i n a te

    c r i t i c a l i s s u e s a n d m a k e t h e m a s i m p l e o b -

    j e c t o f s t u d y . T h e t e n m i n i - la n g u a g e s a re

    p a r t o f a n e f f o r t t o m e e t t h i s n e e d . T h e is-

    s u e s t r e a t e d i n t h e m i n i - l a n g u a g e s a r e c om -

    m o n

    t o m a n y p r o g r a m m i n g l a ng u a g e s,

    e.g.,

    P L / I , ALGOL 60, BASIC, C P L , P A L , FOR-

    TRAN, MAD, LISP, SNOBOL, AXLE, GEDAN-

    KEN, and ISWlM.

    T A B L E I . SUMMARY OF TOPICS TRI~]ATED IN

    EACH MINI-LANGUAGE

    M i n i - T o p i c

    language

    1 S imple ass i gnme nt ,

    t ran sfer of cont rol ,

    and block s t ruc-

    ture

    2 General ized assign-

    ment and the no-

    t ion of locat ions

    3 Genera l ized t ran sfer

    of control

    Commands

    4 F u n c t i o n s

    5 P a s s i n g o f p a r a m e -

    t e r s

    P r o c e d u r e s

    6 Stat ic type checkin g

    7 Dyn ami c type check-

    i ng

    Type checking

    8 S t ruc tu red da t a

    9 S t r i ng manipu l a t i on

    10 Inpu t / ou tpu t

    Appl ica t ions

    Computing Surveys, Vol. 3, No. 3, September 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    3/32

    T h e r e a r e f e w a c c e p t e d p r i n c i p l e s c o n -

    t r i b u t i n g t o a v i a b l e t h e o r y o f l a n g u a g e d e -

    s i g n , d e s p i t e t h e l a r g e n u m b e r o f p r o g r a m -

    m i ng l a n g u a g e s. T h i s is i n d e e d u n f o r t u n a t e ,

    a s t h e a r t o f u s i n g a c o m p u t e r e f f e c t i v e l y

    h in g es c r i t ic a l l y o n o u r u s e o f l a n g u a g e s t h a t

    a c o m p u t e r u n d e r s t a n d s . E a c h m i n i - l a ng u a g e

    p r e se n t e d h e r e w a s m o t i v a t e d b y t h r e e b a si c

    d e s i g n c r i t e r i a : i l l u m i n a t i o n o f s o m e i m -

    p o r t a n t a s p e c t o f c u r r e n t p r o g r a m m i n g

    l a ng u a ge s , b r e v i t y o f d e s c r i p t i o n , a n d a c l e a r

    d i s t i n c t i o n b e t w e e n s y n t a x a n d s e m a n t i c s .

    T h e se c r i t e r ia a r e v a g u e a n d i n c o m p l e t e .

    F u r t h e r m o r e , i s s u e s l i k e t y p e c h e c k i n g ,

    s tr in g m a n i p u l a t i o n , s t r u c t u r e s , a n d i n p u t /

    o u t p u t d e s e r v e s p e ci a l s t u d y . I t is h o p e d

    t h a t t h e m i n i - l a n g u a g e s m a y s e r v e a s a

    b asis f o r s t u d y o f s e v e r a l i m p o r t a n t i s su e s i n

    l an g u ag e d e s ig n .

    T h e m i n i - l a n g u a g e s i l l u m i n a t e s e v e r a l

    d if fi cu lt ie s o f l a n g u a g e i m p l e m e n t a t i o n . F o r

    e x a m p l e , t h e m i n i - l a n g u a g e o n g e n e r a l i z e d

    t r an s f e r o f co n t r o l p o s e s t h e d i f f i cu l t i s s u e o f

    l i n k i n g i d e n t i f i e r s w i t h p r o p e r v a l u e s ; t h e

    t w o m i n i - l a n g u a g e s o n t y p e c h e c k i n g p o s e

    t he p r o b l e m o f r e c o g n i t i o n o f c o n d i t i o n s t h a t

    l ea d t o p r o g r a m e r r o r s ; a n d t h e m i n i - la n -

    g u a g e o n s t r i n g m a n i p u l a t i o n r a i s e s t h e

    q u e s ti o n o f e f fi c i e n c y i n t h e a l g o r i t h m i c

    r e c o g n it i o n o f s t r in g s d e f i n e d b y a g e n e r a t i v e

    g r a m m a r . T h u s t h e m i n i - l a n g u a g e s c o u l d b e

    th e b a s i s f o r a co u r s e o n co m p i l e r d e s ig n o r o n

    p r o p o s e d m e t h o d s o f l a n g u a g e i m p l e m e n t a -

    tion.

    T h e m i n i - l a n g u a g e s a l s o r a i s e i m p o r t a n t

    i s s u es i n t h e a r ea o f f o r m a l d e f in i t i o n o f

    p r o g r a m m i n g l a n g u a g e s . F e w m e t h o d s o f

    f o rm a l d e f i n i t i o n h a v e b e e n a p p l i e d t o g e n -

    e r al iz e d t r a n s f e r o f c o n t r o l , s t r i n g m a n i p u l a -

    t i o n , a n d i n p u t / o u t p u t . B y l i m i t i n g t h e

    v a r i e ty o f s y n t a c t i c a n d s e m a n t i c c o n t e n t

    in e a c h m i n i - l a n g u a g e , i t is h o p e d t h a t w e

    c an b e t t e r f o c u s o n t h e a c c e p t a b i l i t y o f p r o -

    p o s e d s t r a t e g i e s f o r d e a l i n g w i t h t h e i s s u e s

    e n c a p s u l a t e d i n t h e m i n i - l a n g u a g e s . T h e r e

    a re m a n y c r i t e ri a f o r j u d g i n g t h e a c c e p t a -

    b i l i t y o f a p a r t i c u l a r d e f i n i n g m e c h a n i s m .

    C e r t a i n l y a m o n g t h e s e a r e c o n c i s e n e s s o f

    d e f in i t i o n , p e r s p i cu i ty o f d e f in i t i o n , t h e

    a m o u n t o f i n f o r m a t i o n n e e d e d t o u n d e r s t a n d

    t he d e f i n i n g m e c h a n i s m , a n d t h e a b i l i t y o f

    t he d e f i n i n g m e c h a n i s m t o a d a p t i t s e lf t o

    T e n M i n i - L a n g u a g e s * 1 17

    d i f f e r e n t li n g u i s ti c c o n s t r u c t s . I t s e e m s l i k e l y

    t h a t a n a t t e m p t t o d ef in e a l l t e n m i n i -

    l a n g u a g e s b y a n y o n e o f t h e e x i s ti n g m e t h -

    o d s o f f o r m a l d e f i n i t i o n w i l l f a i l t o s a t i s f y

    t h e a b o v e c r i t e r i a , a n d t h a t p e r h a p s a w e d -

    d i n g o f s e v e r a l m e t h o d s i s a l o g i c a l ( a n d f r u i t-

    f u l ) n e x t s t e p t o w a r d a c h i e v i n g a s a t i s f a c -

    t o r y m e t h o d o f f o r m a l d e f in i ti o n .

    I n a n e f f o r t t o k e e p t h e d e s c r ip t i o n s o f t h e

    m i n i - l a n g u a g e s m i n i m a l , t h e f o l l o w i n g d e f in i -

    t i o n s , u n l e s s o t h e r w i s e s t a t e d o r u n u s e d , h o l d

    f o r a l l m i n i - l a n g n a g e s :

    Pr imi t ive ob jec t s

    a r e t h e n a t u r a l n u m b e r s ,

    r e p r e s e n t e d b y t h e n u m e r a l s 0 1 2 . . - .

    Iden t i f i e r s

    c o m p r i s e t h e s y m b o l s A B . • •Z .

    L a b e l s c o m p r i s e t h e s y m b o l s L 1 L 2 . . . .

    L i s t s

    c o n s i s t o f a n i t e m o r a s e r i e s o f t w o o r

    m o r e i t e m s e a c h s e p a r a t e d b y a c o m m a .

    F o r ex a m p le , 1 , 6 , 5 1 , 9 i s a l is t o f n u m er -

    als .

    Sequences a r e d e f i n e d a s a n i t e m o r a s e r i e s

    o f t w o o r m o r e i t e m s e a c h o n a n e w l i n e .

    F o r e x a m p l e ,

    A : = I

    B : = 4

    C : = B

    i s a s e q u e n c e o f a s s i g n m e n t c o m m a n d s .

    I n a d d i t i o n , a c l e a r d i s t i n c t i o n i s m a d e b e -

    t w e e n p r o g r a m s t h a t a r e e r ro n e o u s b e c a u se

    o f t h e i r s y n t a c t ic f o r m a n d p r o g r a m s t h a t

    a r e e r r o n e o u s b e c a u s e t h e y l e a d t o a n u n d e -

    f in e d c o n d i t i o n d u r i n g e x e c u t i o n . I n p a r t i c u -

    l a r, c e r t a i n c o n t e x t - s e n s it i v e r e q u i r e m e n t s

    ( f o r e x a m p l e , t h a t e a c h i d e n t i f i e r i n a p r o -

    g r a m m u s t b e d e c l a r e d ) a r e i m p o s e d o n t h e

    s y n t a x o f s e v e r a l o f t h e m i n i - l a n g u a g e s . A

    p r o g r a m n o t s a t i s f y i n g a l l r e q u i r e m e n t s o f

    i t s s y n t a x i s s a i d t o b e " s y n t a c t i c a l l y i ll e g a l "

    a n d m u s t

    n o t

    b e e x e c u t e d . F u r t h e r m o r e , t h e

    r u l e s f o r e x e c u t i o n o f a p r o g r a m m a y l e a d

    t o a c o n d i t i o n t h a t is u n d e f i n e d a c c o r d i n g

    t o t h e s e r u l e s . S u c h a p r o g r a m i s s a i d t o b e

    " i n v i o l a t i o n , " a n d e x e c u t i o n m u s t t e r m i -

    n a t e a t t h e p o i n t o f v i o l a ti o n . T h e f o ll o w i n g

    c o n d i t i o n h o l d s f o r a l l m i n i - l a n g u a g e s :

    A n y

    at tem pt to eva lua te an iden t if i e r or na m ed ex -

    press ion whose va lue i s unde f ined i s in v io la -

    t ion .

    C o m p u t i n g S u r v e y s , V o l . 3 , N o . 3 , S e p t e m b e r 1 9 7 1

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    4/32

    118 •

    Henry F. Ledgard

    A s i d e f r o m t h e a b o v e c o n v e n t i o n s , t h e d e -

    s c r i p t i o n o f e a c h m i n i - l a n g u a g e i s s e l f - c o n -

    t a i n e d , a n d t h e r e a d e r w h o w i s h e s t o s t u d y

    o n e o r m o r e o f t h e m i n i -l a n g u a g e s s e p a r a t e l y

    m a y d o s o .

    MINI -LANGUAGE 1 :

    S IMPLE ASSIGNM ENT, TRANSFER OF

    C O N T R O L , A N D BL O C K S TR UC TURE

    P r o b a b l y , t h e m o s t c o m m o n f e a t u r e o f e x is t-

    i n g p r o g r a m m i n g l a n g u a g e s i s t h e d e s c r i p -

    t i o n o f c o m p u t a t i o n s b y a s e q u e n c e o f c o m -

    m a n d s . E a c h c o m m a n d i n d i c a te s s o m e s e ri es

    o f o p e r a t i o n s , a p p r o p r i a t e t o t h e l a n g u a g e ,

    t h a t is t o b e p e r f o r m e d o n d a t a . T h e d a t a

    o b j e c t s m a y b e r e p r e s e n t e d d i r e c t l y ( e . g . ,

    t h e n a t u r a l n u m b e r s a r e r e p r e s e n t e d h e r e b y

    t h e n u m e r a l s 0 , 1, 2 , e t c . ) , o r t h e r e m a y a p -

    p e a r i d e n t i f i e r s t h a t , w h e n e v a l u a t e d i n c e r -

    t a i n c o n t e x t s , h a v e v a l u e s t h a t a r e d a t a o b -

    j e ct s. T h e c o m m a n d s a r e g e n e r a l l y e x e e u t e d

    s e q u e n t i a l l y , u n l e s s a c o m m a n d i s e x e c u t e d

    t h a t e x p l i c i tl y a l t e r s t h e s e q u e n t i a l o r d e r .

    H o w e v e r , t w o q u e s t i o n s a r i s e . F i r s t , w h a t

    o b j e c t s a r e a s s o e i a t e d w i t h t h e i d e n t i f i e r s

    u s e d in t h e e x e e u t i o n o f a c o m m a n d ? S e e -

    o n d l y , a f t e r t h e e x e c u t i o n o f a e o m m a n d ,

    w h i c h c o m m a n d i s t o b e e x e c u t e d n e x t ?

    S u c h q u e s t i o n s a r e e s p e c i a l l y b a s l e t o la n -

    g u a g e s t h a t i n c l u d e a s s i g n m e n t , t r a n s f e r o f

    c o n t r o l , a n d b lo c k s t r u c t u r e . M i n i - l a n g u a g e

    1 t r e a t s t h e s e i s s u e s i n s o m e w h a t s i m p l i f ie d

    f o r m . M i n i -l a n g u a g e s 2 a n d 3 t r e a t m o r e

    g e n e r a l i z e d n o t i o n s of a s s i g n m e n t a n d t r a n s -

    f e r o f c o n t r o l .

    Description of Lan gua ge Elements

    Commands

    i n m i n i - l a n g u a g e 1 a r e o f t h r e e

    v a r i e t i e s :

    1) a s im p l e a s s i g n m e n t c o m m a n d , w h i c h

    c o n s i s t s o f a s t r i n g o f t h e f o r m i : = e ,

    w h e r e i i s a n i d e n t i f i e r , a n d e is a n u m e r a l

    o r a n i d e n t i f i e r ;

    2 ) a h o p t o c o m m a n d , w h i c h c o n s i st s o f a

    s t r i n g o f t h e f o r m h o p t o l, w h e r e 1 i s a

    l a b e l ; a n d

    3 ) a b l o c k ( d e f i n e d b e l o w ) .

    A c o m m a n d m a y b e p re f ix e d b y a la b el .

    A declaration

    c o n s i s t s o f a s t r i n g o f t h e

    f o r m i d e n l, w h e r e l is a l is t o f i d e n t i f ie r s ,

    e a c h o f w h i c h m u s t b e d i f fe r e n t .

    A block

    co n s i s t s o f a s t r i n g o f t h e f o r m

    beg i n

    d c e n d , w h e r e d is a d e c l a r a t i o n , a n d

    c i s a s e q u e n c e o f c o m m a n d s s u c h t h a t : 1 )

    e a c h l a b e l p r e f ix i n g a c o m m a n d i n c m u s t b e

    d i f f e r e n t ; a n d 2 ) e a c h l a b e l i n a h o p t o c o m -

    m a n d i n c m u s t b e i d e n t i c a l t o s o m e l a b e l

    p r e f i x in g a c o m m a n d i n c.

    A n i d e n t i f i e r g i v e n i n a d e c l a r a t i o n i s sa id

    t o h a v e a " s c o p e , " w h i c h c o n s i s t s o f t he

    b l o c k i n w h i c h t h e i d e n t i f i e r i s d e c l a r e d a n d

    a l l e n c o m p a s s e d b l o c k s t h a t d o n o t c o n t a i n

    a n o t h e r d e c l a r a t i o n o f t h e s a m e i d e nt if ie r.

    ( N o t e t h a t a l a b e l p r e f ix i n g a c o m m a n d i n c

    m a y b e s a id t o h a v e a " s c o p e " s im i l a r to th a t

    o f a n i d e n t i f ie r . B e c a u s e o f r e q u i r e m e n t (2)

    a b o v e , i t i s n o t n e c e s s a r y i n m i n i - l a n g u a g e 1

    t o e x t e n d t h e c o n c e p t o f t h e s c o p e o f a l a b e l

    t o m o r e d e e p l y n e s t e d b l o c k s . T h i s i s s u e w i l l

    b e t r e a t e d i n m i n i - l a n g n a g e 3 . )

    Program Execution

    E a c h i d e n t i f i e r d e c l a r e d i n a p r o g r a m re -

    f e r s t o a n ( i n i t i a l l y u n s p e c i f i e d ) o b j e c t . T h e

    e x e c u t i o n o f a p r o g r a m b e g i n s w i t h t h e e x e -

    c u t i o n o f t h e o u t e r m o s t b l o c k a n d p r o c e e d s

    a c c o r d i n g t o t h e f o ll o w i n g r u l e s :

    1 ) E a c h c o m m a n d i n a b l o c k i s s e q u e n t ia l l y

    e x e c u t e d u n t i l a h o p t o c o m m a n d (d e-

    f i n e d b e l o w ) i s e n c o u n t e r e d .

    2 ) T h e e x e c u t i o n o f a s i m p l e a s s ig n m e n t

    c o m m a n d o f t h e f o r m i : = e p r o c e e d s as

    f o l l o w s :

    a ) t h e e x p r e s s i o n e i s e v a l u a t e d , a n d i f e

    i s an i d en t i f i e r , i t s v a lu e i s t h e o b j ec t

    c u r r e n t l y a s s i g n e d t o t h e i d e n t i c a l , d e -

    c l a r e d i d e n t i f i e r w h o s e s c o p e i n c l u d e s

    t h e a s s i g n m e n t c o m m a n d ;

    b ) t h e o b j ec t o b t a in ed i n ( a ) i s a s s ig n ed

    a s t h e v a l u e o f t h e i d e n t i f i e r i w h o s e

    s c o p e i n c l u d e s t h e a s s i g n m e n t c om -

    m a n d .

    3 ) T h e e x e c u t i o n o f a h o p t o c o m m a n d of

    t h e f o r m h o p t o l c a u s e s e x e c u t i o n to

    c o n t i n u e ( s e q u e n t i a l ly ) f r o m t h e c om -

    m a n d t h a t i s p r e f i x e d b y t h e l a b el and

    t h a t o c c u r s i n t h e s a m e b l o c k ( no t a

    m o r e d e e p l y n e s t e d b l o c k ) a s th e

    h o p t o c o m m a n d .

    T h e e x e c u t i o n o f a p r o g r a m t e r m i n a t e s

    w h e n t h e e x e c u t i o n o f t h e o u t e r m o s t b lock

    i s t e r m i n a t e d ( u n l e s s , a s m e n t i o n e d e a r l i e r ,

    a v i o l a t i o n c o n d i t i o n a r i s es f r o m a n a t te m p t

    C o m p u t i n g S u r v e y s , V o l . 3 , N o . 3 , S e p t e m b e r 1 9 7 1

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    5/32

    to e v a l u a t e a n i d e n t i f i e r w h o s e v a l u e i s u n -

    specified).

    EXAMPLE i :

    b e g i n i d e n A , B

    A : = i

    B : = 2

    b e g i n i d e n B , C

    B : = A

    C : = 7

    e n d

    A : = 3

    B : = 3

    e n d

    EXAMPLE 2:

    b e g i n i d e n A , B

    A : = i

    B : = 2

    b e g i n i d e n B , C

    B : = A

    C : = 7

    e n d

    h o p t o

    L 1

    A : = 3

    L 1 B : = 3

    e n d

    EXAMPLE 3

    ( S y n t a c t i c a l l y i ll e g a l) :

    b e g i n i d e n A , B

    A : = I

    B : = 2

    b e g i n i d e n B , C

    B : = A

    D : = 7

    e n d

    L 1 A : = 3

    L 1 C : = 3

    e n d

    I n E x a m p l e s 1 a n d 2 , t h e r e a r e f o u r d e -

    c la re d i d e n t i f i e r s : A a n d B i n t h e o u t e r

    b l o c k , a n d B a n d C i n t h e i n n e r b l o c k . L e t

    us r e f e r to the se fou r ide n t i f ie r s as A~, B~,

    B2, a n d C 2. I n E x a m p l e 1 t h e f i n a l v a l u e s o f

    A1, Bj , B2, a n d C2 wil l be 3 , 3 , 1 , an d 7;

    w h e r e a s i n E x a m p l e 2 t h e f i n a l v a l u e s w i l l

    b e 1, 3 , 1, a n d 7 . T h e p r o g r a m o f E x a m p l e 3

    is s y n t a c t i c a l l y q u i t e i ll e ga l , n o t a b l y i n t h a t

    i d en ti f ie r D i s n o t d e c l a r e d , t h e l ab e l L1 p r e -

    fix es t w o c o m m a n d s i n a s i n g l e b lo c k , a n d

    Ten Mini-La,~guages • 119

    i d e n t i f i e r C i n t h e l a s t c o m m a n d i s n o t d e -

    c l a r e d f o r t h e b l o c k i n w h i c h i t o c c u r s .

    Discussion

    T h e n o t i o n s o f a s s i g n m e n t a n d t r a n s f e r o f

    c o n t r o l a r e c h a r a c t e r i s t i c s o f a l m o s t a l l p r o -

    g r a m m i n g l a n g u a g e s . I n t h i s r e s p e c t , p r o -

    g r a m m i n g l a n g u a g e s m a k e a s e r i o u s d e -

    p a r t u r e f r o m c o n v e n t i o n a l m a t h e m a t i c s ,

    w h e r e t h e i m p e r a t i v e m o o d o f c o m m a n d s i s

    n o t u s e d . T h e u s e o f t h e s e i m p e r a t i v e s p r o b -

    a b l y a r o s e f r o m t h e f a c t t h a t , i n t h e i r s i m -

    p l e s t fo r m s , a s s i g n m e n t a n d t r a n s f e r o f c o n -

    t r o l a r e v e r y c l os e t o e q u i v a l e n t c o m m a n d s i n

    m a c h i n e l a n g u a g e s . F r o m t h e u s e r ' s p o i n t o f

    v i e w , m a c h i n e - o r i e n t e d n o t i o n s l ik e s e q u e n c -

    i ng , c r e a t i o n o f d u m m y v a r i a b l e s , a n d s t o r -

    a g e a l l o c a t i o n a r e o f t e n e x t r a n e o u s t o h i s

    o b j e c t i v e .

    I t i s p r o b a b l y f a i r t o s a y t h a t f u t u r e d e -

    v e l o p m e n t s i n p r o g r a m m i n g l a n g u a g e s w il l b e

    l e s s a l g o r i t h m i c ( i . e . , l e s s m a c h i n e - o r i e n t e d )

    a n d m o r e s y n t h e t i c ( i. e. , m o r e g o a l - o r i e n t e d ) .

    F o r e x a m p l e , t h e n o t i o n o f b l o c k s t r u c t u r e

    f r e e s t h e u s e r f r o m c o n c e r n a b o u t t h e w a y i n

    w h i c h t h e s t o r a g e o f v a r i a b l e s i s a l l o c a t e d

    a n d t h e i r c u r r e n t v a l u e s o b t a in e d . O t h e r

    l a n g u a g e d e v e l o p m e n t s ( e . g . , d e f a u l t d e c l a r a -

    t i o n s , t h e p a t t e r n m a tch in g r u l e o f S ~ - O B O L,

    a n d r e e u r s i v e d e f i n it i o n s ) a l so f r e e t h e u s e r

    f r o m u n n e c e s s a r y d e t a il s , s u c h a s e x p li c i t

    s p e c i f i c a t i o n o f t y p e s , s t r i n g s c a n n i n g a l g o -

    r i t h m s , a n d p u s h d o w n s t a c k s .

    M I N I - L A N G U A G E 2 :

    G E N E R A L I Z E D A S S I G N M E N T A N D

    T HE N O T I O N O F L O C A T I O N S

    C o n s i d e r t h e f o ll o w i n g t w o a s s i g n m e n t c o m -

    m a n d s :

    1) ( i f A > B t h e n X e l s e Y ) : = I

    2 ) I : = ( i f A > B

    t h e n

    X e l s e Y )

    T h e t w o e x pr e ss io n s " ( i f A > B

    t h e n

    X e l s e

    Y ) " a n d " I " a r e e v a l u a t e d q u i t e d i f f e r e n t l y

    i n c o m m a n d s ( 1) a n d ( 2) . L o o s e l y sp e a k i n g ,

    i n c o m m a n d (2 ) w e w a n t t o k n o w w h a t

    ob-

    ject is c u r r e n t l y a s s o c i a te d w i t h o n e o f t h e

    i d e n t i fi e r s , X o r Y ; w h e r e a s i n c o m m a n d ( 1)

    w e w a n t t o k n o w w h a t location i s c u r r e n t l y

    r e s e r v e d f o r o n e o f t h e i d e n t i f i e r s , X o r Y ,

    s o t h a t w e c a n u p d a t e i t s c o n t e n t s . T h e d i f -

    Computing Surveys, Vol. 3, No. 3. Seotember 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    6/32

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    7/32

    l o c a t i o n , f o r , u p o n i n v o c a t i o n , t h e f o r m a l

    p a r a m e t e r B o f p r o c e d u r e P i s l i n k e d w i t h

    the

    locat ion

    o f A . H e n c e t h e o c c u r r e n c e o f B

    on t h e l e f t s id e of " B = B + 2 ; " r e f e r s t o t h e

    l o ca ti o n o f A ( w h i c h i s t o b e u p d a t e d ) ,

    w h er ea s t h e o c c u r r e n c e o f B o n t h e r i g h t

    side d e n o t e s t h e v a l u e s t o r e d i n t h e l o c a t i o n

    of A.

    M o s t p r o g r a m m i n g l a n g u a g e s p l a c e r e -

    s t r i c t i o n s o n t h e k i n d s o f e x p r e s s i o n s t h a t

    can d e n o t e l o c a t i o n s . F o r e x a m p l e , t h e c o m -

    mands

    ( i f A > B t h e n X e l s e Y ) : = e

    and

    F ( X ) : = e

    w h e r e e i s an ex p r e s s io n , a r e u s u a l ly p r o -

    h ib it ed , a l t h o u g h t h e r e i s n o c o n c e p t u a l d i fS -

    c u lt y i n v i e w i n g B o o l e a n e x p r e s s i o n s o r f u n c -

    t i o n a l a p p l i c a t i o n s a s b e i n g e v a l u a t e d i n

    " l e f t - m o d e , " i. e ., y i e l d i n g a l o c a t i o n .

    F u r t h e r m o r e , o n e g e n e r a l l y t h i n k s o f a r -

    ra ys a s f u n c t i o n s f r o m a n n - t u p l e o f i n te g e r s

    in to v a l u e s . B u t c o n s i d e r t h e a s s i g n m e n t

    c o m m a n d A [ I] : = A [ I ] + I , w h e r e A is a n

    a r r a y a n d I i s a n i n t e g e r . H e r e A [ I ] o n t h e

    le ft s id e o f t h e c o m m a n d r e a l l y d e n o t e s a

    location,

    a n d t h e o c c u r r e n c e o f A l l ] o n t h e

    r ig h t s i d e d e n o t e s t h e v a l u e s t o r e d i n t h i s

    l o c a t i o n . T h e r e f o r e , w e s h o u l d , p e r h a p s ,

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

    in teger s in to

    l oca t ions .

    W i t h t h i s v i e w , t h e

    a s s i g n m e n t c o m m a n d i s r e a d i l y e x p l a i n e d

    b y c o n s i d e r i n g i t s l e f t s id e a s e v a l u a t e d i n

    l e ft -m o d e a n d i t s r i g h t s i d e i n r i g h t - m o d e .

    I n s u m m a r y , i t a p p e a r s t h a t w e s h o u l d

    face t h e n o t i o n o f lo c a t i o n s i n p r o g r a m m i n g

    l a ng u a ge s w i t h p r o p e r c o n c e r n f o r a d is -

    t i n c t i o n b e t w e e n l o c a t i o n s a n d t h e v a l u e s

    s to r ed t h e r e in .

    M I N I -L A N G U A G E 3 :

    GENERALIZED TRANSFER OF CON TROL

    T h e n o t i o n o f t r a n s f e r o f c o n t r o l i s a t o p i c

    t ha t o f t e n s t im u l a t e s c o n t r o v e r s y , e s p e c i a ll y

    in l a n g u a g e s t h a t p e r m i t l a b e l v a r i a b l e s o r

    l a b e l a r g u m e n t s o f p r o c e d u r e s . M i n i - l a n -

    g ua ge 3 t r e a t s t h i s is s u e b y a u g m e n t i n g m i n i -

    l a ng u a ge 1 t o i n c l u d e t h e n o t i o n s o f a l a b e l

    T e n M i n i - L a n g u a g e s •

    121

    v a r i a b l e a n d o f t r a n s f e r o f co n t r o l b e t w e e n

    b lo ck s .

    Descript ion of Language Elements

    C o m m a n d s i n

    m i n i - l a n g u a g e 3 a r e o f t h r e e

    v a r i e t i e s :

    1 ) a n a s s i g n m e n t c o m m a n d , w h i c h c o n s i s t s

    o f a s t ri n g o f e i t h e r t h e f o r m i : = e o r

    i := l , w h e r e i i s an i d en t i f i e r , e i s a

    n u m e r a l o r a n i d e n t i f i e r , a n d l i s a l a b e l ;

    2 ) a g o t o c o m m a n d , w h i c h c o n s i s ts o f a

    s t r in g o f t h e f o r m g o t o x , w h e r e x is

    a n

    i d e n t i f i e r o r a l a b e l ; a n d

    3 ) a b l o c k ( d e f i n e d b e l o w ) .

    A c o m m a n d m a y b e p r e f ix e d b y a l a b e l.

    A dec lara t ion

    c o n s i s t s o f a s t r i n g o f t h e

    f o r m

    i d e n

    i l , i 2 , " - , i , , w h e r e i i , i 2 ,

    • . - i ~ a r e i d e n t i f i e r s , e a c h o f w h i c h m u s t b e

    d i f f e r e n t .

    A b lock

    c o n s i s t s o f a s t r i n g o f t h e f o r m

    (1)

    b e g i n

    d c e n d , w h e r e d i s a d e c l a r a t i o n ,

    a n d c is a s e q u e n c e o f c o m m a n d s s u c h t h a t

    e a c h l a b e l p re f i x in g a c o m m a n d i n c m u s t b e

    d i f f e r e n t . A n i d e n t i f i e r g i v e n a d e c l a r a t i o n o r

    a l a b e l p r e fi x i n g a c o m m a n d is sa i d t o b e

    " d e c l a r e d , " a n d t o h a v e a " s c o p e " c o n s is ti n g

    o f b l o c k ( 1 ) a b o v e , i n w h i c h t h e i d e n t i f i e r o r

    l a b e l i s d e c l a r e d , a n d a l l e n c o m p a s s e d b l o c k s

    i n c t h a t d o n o t c o n t a i n a n o t h e r d e c l a r a t i o n

    o f t h e s a m e i d e n t i f i e r o r l a b e l .

    A p r o g r a m

    c o n s i s t s o f a b l o c k s u c h t h a t

    e a c h o c c u r r e n c e o f a n i d e n t i f i e r o r l a b e l i n a

    c o m m a n d l i e s w i t h i n t h e s c o p e o f a n i d e n t i -

    c a l , d e c l a r e d i d e n t i f i e r o r l a b e l i d e n t i f i e r .

    The value of a label l

    i n a n a s s i g n m e n t o r

    g o t o c o m m a n d c o n s is t s o f t w o p a r t s : 1 ) t h e

    ( u n i q u e ) c o m m a n d c t h a t i s p r e f i x e d b y 1

    a n d l ie s w i t h i n t h e s c o p e o f l ; a n d 2 ) t h e

    " e n v i r o n m e n t " f o r c ; i .e ., a p a i r i n g o f t h e

    i d e n t i f i e r s w h o s e s c o p e in c l u d e s c w i t h t h e

    l oca t ions

    i n w h i c h t h e i r c u r r e n t v a l u e s a r e

    s t o r e d .

    Program Execution

    E a c h i d e n t if i e r i n a p r o g r a m r e f e r s t o a n

    ( i n i t i a l l y u n s p e c i f i e d ) o b j e c t . T h e e x e c u t i o n

    o f a p r o g r a m b e g i n s w i t h t h e e x e c u t i o n o f

    t h e o u t e r m o s t b l o c k a n d p r o c e e d s a c c o rd i n g

    t o t h e f o l l o w i n g ru l e s :

    1) T h e e x e c u t i o n o f a b l o c k r e s u l ts i n t h e

    a l l o c a t i o n o f

    n e w

    l o c a t i o n s f o r i d e n t i f i e r s

    t h a t a r e l o c a l t o t h e b l oc k , fo l l o w e d b y

    Co m p u t in g S u rv ey s , Vo l . 3 , No . 3 , S ep t em b er 1 9 71

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    8/32

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    9/32

    2) T h e n u m e r a l 5 is p r in t e d . T h e c o m -

    m a n d " g o t o X " w o u l d b e h a v e a s i f i t

    w e re w r i t t e n a s " g o t o L 2 "

    3) T h e n u m e r a l 3 is p r i n t e d . A f t e r e x i t f r o m

    t h e i n n e r b l o c k t h e f i r s t t i m e , t h e e n -

    v i r o n m e n t f o r L 2 w o u l d l i n k B w i t h t i l e

    v a lu e 2 . T h e c o m m a n d " g o t o X " w o u ld

    r e s e t t h e e n v i r o n m e n t f o r th e i n n e r b l o c k

    s o t h a t t h e v a l u e o f B w o u l d b e 2 , a n d

    t r a n s f e r o f c o n t r o l w o u l d s u b s e q u e n t l y

    u p d a t e t h e v a l u e o f B t o 3 , w h i c h w o u l d

    b e p r i n t e d .

    A s m e n t i o n e d e a r li e r, t h e n o t i o n o f t r a n s -

    f er o f c o n t r o l i s a d i ff i c u lt a n d d e b a t a b l e

    i s s u e . R e a d e r s w i s h i n g a m o r e d e t a i l e d d i s -

    c u ss io n o f t h i s s u b j e c t a r e r e f e r r e d t o t h e

    i ll u m i n a ti n g p a p e r b y J o h n s t o n [6 ].

    O t h e r i s s u e s r e g a r d i n g t r a n s f e r o f c o n t r o l

    a re a ls o w o r t h p o i n t i n g o u t . D o e s t r a n s f e r o f

    c on tro l m a k e p r o g r a m d e b u g g i n g m u c h m o r e

    d i f f i c u l t ? S h o u l d t r a n s f e r o f c o n t r o l o u t o f

    p r o c e d u r e s o r i n t o m o r e d e e p l y n e s t e d b l o c k s

    be a l lo w e d ? W h a t d o e s " g o t o x , " w h e r e x

    is a l a b el v a r i a b l e , m e a n w h e n t h e c o m m a n d

    is e x e c u t e d d u r i n g r e c u r s i v e p r o c e d u r e c a ll s?

    H o w d i ff ic u l t is i t to i m p l e m e n t o r f o r m a l l y

    d efin e a g e n e r a l i z e d t r a n s f e r o f c o n t r o l

    f a ci li ty ? I n s h o r t , i s t h e n o t i o n o f t r a n s f e r

    of c o n t ro l a u s e fu l f e a t u r e o f p r o g r a m m i n g

    l a n g u a g e s ?

    O n e of t h e c a u s e s f o r t h e d e b a t e o v e r

    t r a n s f e r o f c o n t r o l i s t h a t w e l o s e t h e p r o p -

    e r ty o f r e f e r e n t i a l t r a n s p a r e n c y [1 3]; t h a t

    is, w e c a n n o l o n g e r i s o la t e a n a r b i t r a r y

    p o rt io n o f a p r o g r a m a n d c o n c e p t u a l l y r e -

    p l a c e i t b y i t s v a l u e . F o r e x a m p l e , c o n s i d e r

    a p r o c e d u r e d e c l a r a t i o n o f t h e f o r m

    d e c l a r e

    p r o c e d u r e P ( X , Y ) ;

    0 ; c 2 ; ' ' '

    ; C n ;

    e n d

    w h e r e C l, c 2 , • • • , cn a r e c o m m a n d s w h o s e

    e ff ec ts a r e l o c al to t h e p r o c e d u r e b o d y . T h e

    " v a l u e " o f s u c h a p r o c e d u r e m i g h t b e t h e

    f u n c t i o n f o r c o m p u t i n g t i l e g r e a t e s t c o m -

    m o n d i v i s o r o f X a n d Y o r a s to r e t o s t o r e

    t r a n s fo r m a t i o n , s w a p p i n g t h e v a l u e s o f X

    a n d Y . I f w e a d d t h e p o s s i b i l it y t h a t o n e o f

    th e c o m m a n d s c l , c 2 , • • • , c ~ m a y r e s u l t i n

    a t r a n s f e r o f c o n t r o l o u t o f th e p r o c e d u r e

    b o d y , t h e n w e c a n n o l o n g e r i s o l a t e i t s

    T e n M i n i - L a n g u a g e s • 123

    " v a l u e , " a s w e m a y l e a v e th e p r o c e d u r e a n d

    i ts s u p p o s e d p o i n t o f r e t u r n .

    M o r e g e n e r a l l y , t h e u s e o f t r a n s f e r o f c o n -

    t ro l m a k e s t h e a r t o f p r o g r a m m i n g m o r e

    s e q u e n c e - o r i e n t e d a n d l e s s g o a l - o r i e n t e d .

    F u r t h e r m o r e , a s i n m i n i - l a n g u a g e 3 , t h e r e

    a r e o t h e r s i d e - e f fe c t s a s s o c i a t e d w i t h a g e n -

    e r a l i z e d t r a n s f e r o f c o n t r o l f a c i l i t y : n a m e l y ,

    t h e n o t i o n s o f w h i c h v a r i a b l e s a r e a c t i v a t e d

    a n d t o w h i c h v a l u e s t h e y a r e t o b e l in k e d .

    T h e s e p r o b l e m s i n d i c at e t h a t t h e n o t i o n o f

    t r a n s f e r o f c o n t r o l s h o u l d b e s t u d i e d w i t h a

    c a r e fu l e y e t o w a r d m a k i n g i t s d e f in i ti o n a n d

    i m p l e m e n t a t i o n s im p l e r.

    M I N I - L A N G U A G E 4 : F U N C T I O N S

    O n e o f th e m o s t u s e f u l f e a t u r e s o f m a n y

    p r o g r a m m i n g l a n g u a g e s i s t h e a b i l i t y t o

    d e fi n e a n d a p p l y f u n ct io n s . M i n i - la n g u a g e 4

    i s d e v o t e d e x c l u s i v e l y t o t h e n o t i o n o f a

    f u n c t i o n a n d is d e v o i d o f c o m m a n d f e a t u r e s .

    T h i s m i n i - l a n g u a g e t r e a t s f u n c t i o n s a s fi r st -

    c l a s s m a t h e m a t i c a l o b j e c t s ; i n p a r t i c u l a r ,

    t h e v a l u e o f a n i d e n t i fi e r o r a n e x p r e s s i o n c a n

    b e a f u n c t i o n , a n d f u n c t i o n s w h o s e d o m a i n

    a n d r a n g e m a y i n c l u d e o t h e r f u n c t i o n s c a n

    b e d e f i n e d . M i n i - l a n g u a g e 4 i s b a s e d o n t i l e

    a p p l i c a t i v e e x p r e s s i o n s o f P e t e r L a n d i n [ 8] ,

    w h i c h , i n t u r n , a r e b a s e d o n t h e X - c a l c u l u s

    o f C h u r c h [1] a n d C u r r y [ 3 ] , a n d o n t h e

    m a t h e m a t i c a l n o t i o n o f a f u n c t io n .

    Descr ipt ion of Language E lements

    Pr imi t ive ob jec t s

    i n m i n i - l a n g u a g e 4 i n -

    c l u d e , i n a d d i t i o n t o t h e n a t u r a l n u m b e r s :

    1 ) a b i n a r y f u n c t i o n , w h i c h m a p s t w o n a t -

    u r a l n u m b e r s i n t o t h e n a t u r a l n u m b e r t h a t

    is t h e i r n u m e r i c a l s u m ; a n d 2 ) a q u a r t e r n a r y

    f u n c t io n , w h i c h m a p s f o u r o b j e c t s - - o f w h i c h

    t h e f ir st t w o a r e n a t u r a l n u m b e r s a n d t h e

    s e c o n d t w o a r e a r b i t r a r y o b j e c t s - - i n t o t h e

    t h i r d o b j e c t i f t h e f ir s t n a t u r a l n u m b e r i s

    g r e a t e r t h a n t h e s e c o n d a n d i n t o t h e f o u r t h

    o b j e c t i f t h e o p p o s i t e is t ru e . T h e s e b i n a r y

    a n d q u a r t e r n a r y f u n c ti o n s a r e r e p r e s e n te d

    b y t h e s y m b o l s

    +

    a n d " s e l e c t , " r e -

    s p e c t i v e l y .

    A s i mp l e e x p r e s s i o n

    i s e i t h e r o n e o f t h e

    p r i m i t iv e s y m b o l s { +

    s e l e c t

    0 1 2 . . . } o r

    a n i d e n t if ie r . T h e v a l u e o f a p r i m i t i v e s y m b o l

    Computing Surveys, Vol. 3, No. 3, September I971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    10/32

    124 •

    H e n r y F . L e d g a r d

    i s t h e p r i m i t i v e o b j e c t r e p r e s e n t e d b y t h e

    s y m b o l . T h e v a l u e o f a n i d e n t i f i e r i s t h e

    o b j e c t c u r r e n t l y l i n k e d w i t h t h e i d e n t i f i e r

    ( f o r l i n k i n g o f i d e n t i f i e r s t o o b j e c t s , s e e

    d e f i n i t i o n a n d e v a l u a t i o n o f " l e t " e x p r e s -

    s io n s , b e lo w ) .

    A l i s t expre ss ion

    i s a l i s t o f ex p r e s s io n s .

    T h e v a l u e o f a li s t e x p r e s s i o n e j ,

    e 2 , ,

    e . , w h e r e t h e e l ( 1 ~ i ~ n ) a r e e x p r e s s i o n s ,

    i s t h e l i s t o f o b j e c t s a t , a 2 , • • - , a ~ o b t a i n e d

    b y e v a l u a t i n g ( in a n y o r d e r ) e a c h o f t h e

    c o m p o n e n t e x p re s si o ns e j ,

    e 2 , • • • , en •

    A c o m b i n a t i o n

    i s a s t r i n g o f t h e f o r m

    r ( l ) ,

    w h e r e r i s a n i d e n t i f i e r o r o n e o f t h e p r i m i t i v e

    s y m b o l s d - o r

    s e l e c t ,

    an d l i s a l i s t ex p r e s -

    s io n . T h e v a l u e o f a c o m b i n a t i o n i s o b t a i n e d

    b y e v a l u a t i n g r a n d l a n d t h e n a p p l y i n g

    t h e v a l u e o f r t o t h e v a l u e o f l. T h i s e v a l u a -

    t i o n i s w e l l - d e f i n e d ( i . e . , n o t i n v i o l a t i o n )

    o n l y i f : t h e v a l u e o f r i s a f u n c t i o n ; t h e

    n u m b e r o f t h e c o m p o n e n t s o f l is t e x p re s s i o n

    l is i d e n t i c a l t o t h e n u m b e r o f a r g u m e n t s o f

    t h e f u n c t i o n ; a n d i f r is o n e o f t h e s y m b o l s d -

    o r s e l e c t , t h e v a l u e s o f t h e f i r s t t w o a r g u -

    m e n t s o f l m u s t b e n a t u r a l n u m b e r s .

    T h e f o l lo w i n g a l t e r n a t e n o t a t i o n s m a y b e

    u s e d f o r c o m b i n a t i o n s :

    i n p l a c e o f

    (el + e2)

    -4- (e l, e2)

    a n d

    ( i f e l > e2 t h e n ea e l s e e4)

    i n p l a c e o f

    s e l e c t

    (el , e2, ca, e4).

    A l et expre ss ion i s a s t r i n g o f e i t h e r t h e

    f o r m

    1)

    l e t

    i = el

    i n

    e2

    o r

    2) l e t f ( x t , . . . , x ~ ) = e l i n e2

    w h e r e i i s a n i d e n t i f i e r, f , X l , " . . , x ~ a r e

    i d e n t i f i e r s e a c h o f w h i c h m u s t b e d i f f e r e n t ,

    a n d e l a n d e2 a r e e x p r e s s i o n s . T h e v a l u e o f a

    l e t e x p r e s s i o n o f f o r m (1 ) is c o m p u t e d b y

    e v a l u a t i n g e l , l i n k i n g i w i t h t h e v a l u e o f e ~,

    a n d t h e n e v a l u a t i n g e 2 . T h e v a l u e o f a le t

    e x p r e s s i o n o f f o r m ( 2) i s c o m p u t e d b y f o r m -

    i n g t h e f u n c t i o n m a p p i n g n a r g u m e n t s i n to

    t h e v a l u e o f t h e e x p r e s s i o n e t o b t a i n e d b y

    l i n k i n g t h e i d e n t i f i e rs x l , • • . , x ~ w i t h t h e i r

    r e s p e c t i v e a r g u m e n t s , a n d l i n k in g i d en t if ie r s

    o t h e r t h a n X l , . . . , xn w i t h t h e i r c u rr e n t

    v a l u e s ; l i n k i n g f w i t h t h e f u n c t i o n t h u s

    f o r m e d ; a n d t h e n e v a l u a t i n g e 2 .

    I f t h e i d e n t i f i e r f i t s e l f a p p e a r s i n el a n d

    is n o t l i n k e d b y a n o t h e r l e t e x p r e s s io n t h a t is

    a s u b c x p r e s s i o n o f e l , t h e n t h e o c c u r r e n c e of

    f i s t a k e n a s p a r t o f a r e c u r s i v e d e f i n i t i o n o f

    f . F o r e x a m p l e , t h e l e t e x p r e s s i o n s :

    1 ) l e t Y = 3

    2)

    l e t

    F ( X ) = ( X + X )

    3 ) l e t G ( N ) = ( i f N > 3 t h e n 1 e l s e G ( 5) )

    l i n k Y , F , a n d G w i t h o b j e c t s w h o s e e f f e c -

    t i v e v a l u e s a r e , r e s p e c t i v e l y : 1 ) t h e n a t u r a l

    n u m b e r t h r e e ; 2 ) th e f u n c t i o n m a p p i n g a

    n a t u r a l n u m b e r i n t o i t s d o u b l e ; a n d 3 ) t h e

    f u n c t i o n m a p p i n g a n a t u r a l n u m b e r i nt o

    t h e c o n s t a n t v a l u e o n e .

    A n

    e x p r e s s i o n

    i s e i t h e r a s im p le ex p r e s s io n ,

    a l i s t ex p r e s s io n , a l e t ex p r e s s io n , o r a co m -

    b i n a t i o n .

    Program Execution

    A p r o g r a m i s

    a n e x p r e ss i o n . T h e v a l u e o f a

    p r o g r a m i s t h e v a l u e o f t h e e x p r e s s i o n . N o t e

    t h a t ( a s m e n t i o n e d i n t h e f i r s t s e c t i o n ,

    " G e n e r a l C o n s i d e r a t i o n s " ) i f t h e e v a l u a t i o n

    o f a p r o g r a m l e a d s t o t h e e v a l u a t i o n o f a n

    i d e n t i f i e r t h a t i s n o t l i n k e d t o a v a l u e r - t h e

    p r o g r a m is in v i o l a t i o n .

    E X A M P L E 1 :

    l e t F ( Y ) = ( Y + 3 )

    i n

    ( F ( 1 ) d - F ( 2 ) )

    E X A M P L E 2 :

    l e t F ( X ) = ( X + X )

    i n l e t G ( P , X ) = ( P ( X ) + P ( 1 ) )

    i n G ( F , 2 )

    E X A M P L E 3 :

    l e t

    F ( X ) = ( if X > 3

    t h e n

    X

    e l s e ( X + F ( X + l ) )

    i n

    F ( 2 )

    E X A M P L E 4 :

    l e t Y = 2

    i n l e t F ( X ) = ( X + Y )

    i n F

    Computing Surveys , Vol. 3 , No. 3 , September 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    11/32

    E X A M P L E 5

    le t P ( F , G , N ) = ( i f N > 1 0 0 t h e n 1 e l s e

    G(F, G(N+I)))

    i n l e t

    Q(F, G, N) = (if N > 100 t hen i

    e l s e

    F(F, G(N+I)))

    i n P ( P , Q , 86 )

    The values of the example programs above

    are: Example 1, the natu ral number 9;

    Example 2, the natural number 6; Example

    3, the natural number 9; Example 4, the

    function mapping some object X (presum-

    ably a natural number) into a summation of

    X and the natural number 2; and Example

    5, the natural number 1.

    i s c u s s i o n

    The notion of functions is a well-accepted

    and useful feature of conventional mathe-

    matics, and notions akin to functions (e.g.,

    procedures and subroutines) have been duly

    incorporated into most programming lan-

    guages. However, one must be quite careful

    when one tries to model such programming

    language constructs like procedures and sub-

    routines with functions. Consider the simple

    A L G O L 6 0

    procedure declaration:

    i n t e g e r p r o c e d u r e P ( X ) ; i n t e g e r X ;

    P := X := X+X

    Mathematically, P is not a function of type

    I---~I, from integers into integers. The no-

    tion of assignment in programming lan-

    guages, in conjunction with function-like

    procedures, forces us to consider

    l oca t ions

    of identifiers as part of our universe of dis-

    course [16]. In particular, let I be the set of

    integers, L be a set of locations for the

    identifiers in a program, and S (the stores

    of values for a program) be a set of functions

    mapping the locations of identifiers into

    integers. Mathemat ical ly, P is a function

    L X S --~ I X S. That is, P takes the loca-

    tion, 1EL, of its argument and a store,

    slES, as inputs, and returns an integer,

    iCI, and a new store, s~ES, as outputs. The

    integer i depends on the integer value stored

    in location l of sl, and the new store, s=ES,

    reflects the side-effect. Hence when we in-

    voke P in an expression such as

    3 + P(Y) + Y

    T e n M i n i - L a n g u a g e s • 125

    two events occur: the first member, i E I of

    ( 4

    s) E I × S, is added to 3, and the second

    member, s2E S (which reflects the changed

    value in the location of Y in S), is used to

    obtain subsequent values of Y.

    Furthermore, consider the Lisp doublets:

    DEFINE ((

    (F (LAMBDA X) (LAMBDA (Y) X)))

    ))

    F 1 )

    Mathematically, the value of F(1) is the

    cons tant function mapping any argument

    into the integer one. However, the valua-

    tion of F(1) in Lisp yields an error. There-

    fore, in LisP, functions can only appear in

    constructs where they will subsequently be

    applied to arguments yielding

    va lues

    that

    are n o t functions.

    For many programming languages, there

    are two other features of functions that do

    not fit their mathematical counterparts.

    First, many programming languages are

    generous in the kinds of objects that can be

    used as arguments to functions, but restrict

    the kinds of objects that can be returned as

    values. For example, ALGOL 60 procedures

    can take numbers, Boolean values, labels,

    switches, arrays, and procedures as argu-

    ments, but can return only numbers and

    Boolean values as results. Such restrictions

    inhibit the usefulness of the language.

    Secondly, the notion of recursive defini-

    tion of functions is a feature of programming

    languages that is avoided by many pro-

    grammers and language implementers.

    Mathematically, recursive definitions are

    often a more succinct notation than inter-

    active definitions. Consider the following

    two definitions of a function TOTAL ,

    which takes a one-dimensional array A and

    integer N as arguments and returns the sum

    of the N elements A[1] through A[N]:

    T O T A L : P R O C ( A , N ) ; A R R A Y A , I N T E G E R I , N , Z ;

    Z : = A [ N ]

    I : =

    N ;

    L : I F I = 1 T H E N G O T O M ;

    I : = - 1;

    Z : = Z + A [ I ] ;

    G O T O L ;

    R E T U R N Z ;

    :

    E N D T O T A L ;

    C o m p u t i n g S u r v e y s , V o l . 3 , N o . 3 , S e p t e m b e r 1 9 7 1

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    12/32

    126 •

    He nry F . L e dg ard

    a n d

    TOT AL (A, N) = IF N = 1 TH EN A[N]

    ELSE A[N] + TOTAL (A, N -- 1);

    I t i s c l a i m e d t h a t t h e s e c o n d d e f i n i t i o n i s

    m u c h m o r e t r a n s p a r e n t b e c a u s e i t a v o i d s

    u n n e c e s s a r y d e t a i l s , i n t h i s e a s e t h e n o t i o n

    o f s e q u e n c e o f o p e r a t i o n s .

    I t is h o p e d t h a t f u t u r e d e v e l o p m e n t s in

    p r o g r a m m i n g l a n g u a g e s w i l l f u l l y r e c o g n i z e

    t h e n o t i o n o f f u n c t io n s a n d t h e i r i m p o r t a n t

    m a t h e m a t i c a l p r o p e rt ie s .

    M I N I - L A N G U A G E 5 :

    P A S S I N G O F P A R A M E T E R S

    O n e o f t h e m o r e c o n f u s i n g f e a t u r e s o f p r o -

    g r a m m i n g l a n g u a g e s i s t h e n o t i o n o f p a s s i n g

    o f p a r a m e t e r s . T h e i n t e n t o f m i n i - l a n g u a g e 5

    is t o d is t in g u i s h t h r e e c o m m o n l y u s e d m e t h -

    o d s f o r p a s s i n g p a r a m e t e r s , h e r e d e n o t e d a s

    " c a l l b y c o p y v a l u e , " " c a l l b y l o c a t i o n , "

    a n d " c a l l b y e x p r e s s i o n . " T h e s e t h r e e m e t h -

    o d s a re b a s e d o n t h e " c a l l b y v a l u e " o f

    A LG O L 6 0 , " c a l l b y r e f e r e n c e " o f C P L , a n d

    " c a l l b y n a m e " o f A LG O L 6 0.

    Descr ipt ion of Language E lements

    Array ide~ti f iers

    a r e c o m p r i s e d o f t h e

    s y m b o l s A I A 2 . . . . T h e v a l u e o f a n a r r a y

    i d e n t i fi e r i s a o n e - d i m e n s i o n a l a r r a y w i t h t e n

    ( i n i t i a l l y u n s p e c i f i e d ) e l e m e n t s . Procedure

    identifiers

    c o m p r i s e t h e s y m b o l s P 1 P 2 . . . ,

    a n d

    parameter identifiers

    c o m p r i s e t h e

    s y m b o l s a b • • • z.

    A parameter specification

    i s a s t r i n g o f

    o n e o f t h e f o l lo w i n g f o r m s : e x p l, c o p y v a l l,

    o r l o c l, w h e r e 1 is a l is t o f p a r a m e t e r i d e n t i -

    f iers . A

    procedure declaration

    i s a s t r i n g o f t h e

    f o r m

    p r o e p(l) s c

    e n d , w h e r e p is a p r o c e -

    d u r e i d e n t i f i e r , l a l i s t o f p a r a m e t e r i d e n t i -

    t ie r s, s a s e q u e n c e o f p a r a m e t e r s p e c i f i c a -

    t io n s , a n d c is a s e q u e n c e o f a s s i g n m e n t c o m -

    m a n d s ( d e fi n ed b e lo w ) s u c h t h a t : e a c h

    p a r a m e t e r i d e n t i f i e r i n l i s d i f f e r e n t ; e a c h

    p a r a m e t e r i d e n t i f i e r i n s i s d i f f e r e n t a n d

    o c c u r s a s o n e o f t h e p a r a m e t e r s in l ; a n d

    e a c h i d e n t i f i e r i n c i s a p a r a m e t e r i d e n t i f i e r .

    F o r e x a m p l e , t h e f o l l o w i n g d e c l a r a t i o n r i o -

    l a r e s e a c h o f t h e a b o v e r e q u i r e m e n t s

    p r o c P l ( a , b , a )

    e x p a , d

    l o c

    a

    D : = I

    e n d

    A n expression is e i th e r a n u m e r a l o r a

    n a m e d e x p r e s s io n . A n a m e d e x p r e s s i o n is

    e i t h e r a n i d e n t i f i e r , a p a r a m e t e r i d e n t i f i e r ,

    o r a n a r r a y i d e n t i f i e r f o l l o w e d b y a n e x p r e s -

    s i o n e n c l o s e d i l l s q u a r e b r a c k e t s .

    A n

    ass ignme~t command

    i s a s t r i n g o f t h e

    f o r m e l : = e 2 , w h e r e e l i s a n a m e d e x p re s -

    s i o n , a n d e2 i s a n e x p r e s s i o n . T h e e x e c u t i o n o f

    a n a s s i g n m e n t c o m m a n d r e s u l t s i n a s s i g n -

    i n g t h e v a l u e o f e2 t o t h e l o c a t i o n d e n o t e d b y

    e ~ . ( F o r a m o r e d e t a i l e d d i s c u s s i o n o f a s si g n-

    m e n t , s e e m i n i - l a n g u a g e 2 . ) I n p a r t i c u l a r , i f

    e~ o r e2 c o n t a i n s a n e x p r e s s i o n o f t h e f o r m

    a[e],

    w h e r e a i s a n a r r a y i d e n t i f ie r a n d e i s a n

    e x p r e s s i o n w h o s e v a l u e is t h e n a t u r a l n u m b e r

    n , t h e n

    a[e]

    d e n o t e s t h e ~ tth e l e m e n t o f t h e

    a r r a y a . *

    A procedure command

    i s a s t r i n g o f th e f o r m

    p(l) ,

    w h e r e p i s a p r o c e d u r e i d e n t i f i e r , a n d

    1 i s a l is t o f e x p r e s s i o n s . T h e e v a l u a t i o n o f

    t h e p r o c e d u r e c o m m a n d o f th i s f o r m is a s

    f o l l o w s :

    1) O b t a i n t h e s e q u e n c e o f a s s ig n m e n t c o m -

    m a n d s e g i v e n i ll t h e d e c l a r a t i o n o f p .

    2 ) F o r e a c h p a r a m e t e r i c a l l e d b y " e x p r e s -

    s i o n , " r e p l a c e e a c h o c c u r r e n c e o f i in c

    b y t h e c o r r e s p o n d i n g e x p r e s s i o n e i n 1 .

    3 ) F o r e a c h p a r a m e t e r i c a l l e d b y " c o p y

    v a l u e , " p r e fi x t o c t h e c o m m a n d i : = e,

    w h e r e e i s t h e c o r r e s p o n d i n g e x p r e s s i o n

    for i in l .

    4 ) F o r e a c h p a r a m e t e r i c a l l e d b y " l o c a -

    t i o n , " o b t a i n t h e c o r r e s p o n d i n g e x p r e s -

    s ion e fo r i : i f e i s an i den t i f i e r , l e t L~

    d e n o t e i t s l o c a t i o n ; a n d i f e i s a n a r r a y "

    e x p r e s s i o n A [ e '] , l e t L ~ d e n o t e t h e l o c a -

    t i o n o f t h e r~ th e l e m e n t o f A , w h e r e n is

    t h e v a l u e

    e'.

    T h e n r e p l a ce e a c h o c c u rr e nc e

    o f i i n c b y L ~ .

    5 ) E x e c u t e t h e s e q u e n c e o f a s s i g n m e n t c o m -

    m a n d s c ' , f o r m e d b y t h e a b o v e r u l e s ,

    w i t h th e f o l lo w i n g i n t e r p r e t a t i o n f or

    * Fo r example, i f the value of the a rray nam e

    A1 is the array w hos e ten elem ents are 4,A,A,5,5,

    A,1,2,3,4 (where A denotes an unspecif ied ele-

    ment) , then the value of Al[7] is 1, and the value

    of Ai[AI[7]] is 4.

    Computing Surveys, Vo/. 3, No. 3, September 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    13/32

    p a r a m e t e r s c a l l e d b y l o c a t i o n : i f a n L g

    i s e v a l u a t e d o n t h e

    r igh t -hand

    s i d e o f a n

    a s s i g n m e n t c o m m a n d , i t s v a l u e i s t h e

    o b j e c t c u r r e n t l y s t o r e d i n t h e l o c a t i o n L ~ ;

    a n d i f a n L ~ a p p e a r s o n t h e

    le f t -hand

    s ide

    o f a n a s s i g n m e n t c o m m a n d , t h e a s s ig n -

    m e n t o f t h e v a l u e o f t h e r i g h t - h a n d s id e

    is m a d e t o t h e l o c a t i o n L ~ .

    Program Execution

    A pr og r am

    c o n s i s t s o f a s e q u e n c e d o f

    p r o c e d u r e d e c l a r a t i o n s f o l l o w e d b y a s e-

    q u e n c e c o f a s s i g n m e n t a n d p r o c e d u r e c o m -

    m a n d s s u c h t h a t :

    1) e a c h d e c l a r e d p r o c e d u r e i d e n t i f i e r in d

    i s d i f f e r en t ;

    2 ) e a c h p r o c e d u r e i d e n t i f i e r i n c i s d e c l a r e d

    in d ;

    3) t h e n u m b e r o f e x p r e s s i o n s in t h e e x p r e s -

    s i o n l i s t o f a p r o c e d u r e c o m m a n d i s

    i d e nt ic a l t o t h e n u m b e r o f p a r a m e t e r s i n

    t h e c o r r e s p o n d i n g p r o c e d u r e d e c l a r a -

    t i o n ;

    4 ) n o p a r a m e t e r i d e n t i f i e r s o c c u r i n

    c;

    a n d

    5 ) n o p r o c e d u r e d e c l a r a t i o n i n d c o n t a i n s a

    p a r a m e t e r t h a t i s c a l l e d b y l o c a t i o n ,

    a p p e a r s o n t h e l e f t si de o f a n a s s i g n m e n t

    s t a t e m e n t , a n d c o r r e s p o n d s t o a n e xp r e s -

    s io n t h a t i s a n u m e r a l - - i . e . , a c o n d i t i o n

    t h a t l e a d s t o a n a s s i g n m e n t t o a n u m e r a l

    i s s y n t ac t i c a l l y i l l eg a l .

    EXAMPLE

    1 :

    p r o c P 1

    (a, b)

    c o p y

    v a l

    a, b

    X : = a

    a : ~ - b

    b :~ x

    e n d

    I : = 3

    A [ I ] := 6

    P1 ( I , A [ I ] )

    E X A M P L E 2 :

    p r o c P2(a , b )

    l o c a t i o n a , b

    x : = a

    a : = b

    b : = x

    e n d

    I : = 3

    A[I ] := 6

    P 2 ( I , A [ I ] )

    T e n M i n i - L a n g u a g e s •

    127

    E X A M P L E 3 :

    p r o c P 3 ( a , b )

    e x p a , b

    x : = a

    a : = b

    b : = x

    e n d

    I : = 3

    a [ I ] : = 6

    P 3 ( I , h [ I ] )

    S u p p o s e w e w i s h t o d e f i n e a n d u s e a p r o -

    c e d u r e t h a t s w a p s t h e v a l u e s o f i t s tw o a r g u -

    m e n t s , a n d w e m u s t s e l e c t o n e of t h e t h r e e

    o p t i o n s a b o v e . W h i c h o n e s h a l l w e c h o o s e ?

    T h e t h r e e e x a m p l e s a r e i d e n t i c a l e x c e p t

    t h a t t l l e p a r a m e t e r s p e c i f i c a t i o n s i n p r o c e -

    d u r e s P 1 ,

    1)2,

    a n d P 3 a r e d i f f e r e n t .

    I n E x a m p l e 1 : t h e v a l u e s o f I a n d A [3 J

    w i l l b e s e t t o 3 a n d 6 , r e s p e c t i v e l y ; a n d

    t h e p r o c e d u r e c a l l P I ( I , A [ I ] ) w i l l b e e x e -

    c u t e d - i . e . , t h e v a l u e s o f a a n d b w i ll b e s e t

    t o 3 a n d 6 , r e s p e c t i v e l y , a n d t h e v a l u e s o f

    x , a , an d b w i l l b e s e t t o 3 , 6, an d 3 , re s p ec -

    t i v e l y . T h e v a l u e s o f I a n d A [ 3] w i ll r e m a i n

    u n c h a n g e d , s o w e s h a l l n o t e l e c t P 1 .

    I n E x a m p l e 2 : t h e v a l u e s o f I a n d A [3 ]

    w i l l b e s e t t o 3 a n d 6 , r e s p e c t i v e l y ; a n d

    t h e p r o c e d u r e c a l l P 2 ( I , A [ I ] ) w i l l b e e x e -

    c u t e d - i . e . , t h e l o c a t i o n s La o f I a n d L b o f

    A [ I ] w i l l b e d e t e r m i n e d , a n d t h e c o m m a n d s

    x : = L a , L a : = L b , a n d L b : = x w i ll b e

    e x e c u t e d , w h i c h w i l l r e s u l t i n s e t t l i n g t h e

    v a l u e s o f I a n d A [3 1 t o 6 a n d 3 , r e s p e c t i v e l y .

    T h u s , p r o c e d u r e P 2 o f E x a m p l e 2 y i el d s t h e

    d e s i r e d o u t c o m e .

    I n E x a m p l e 3 w e h a v e a r a t h e r s u r p r i s i n g

    r e s u l t :

    1 ) t h e v a lu e s o f I a n d A [ 3] w i l l b e s e t t o 3 an d

    6, r e s p e c t i v e l y ; a n d

    2 ) t h e p r o c e d u r e c a l l P 3 ( I , A [ I ] ) w i l l b e

    e x e c u t e d - - i . e . , t h e c o m m a n d s

    X :~-- I

    I : = A i I ]

    A[I ] := x

    w i l l b e e x e c u t e d , w h i c h w i l l r e s u l t i n 3

    b e i n g a s s i g n e d t o x , 6 t o I , a n d t h e n 3

    t o

    A[6] .

    T h e r e f o r e , w e e l e c t

    o~ dy

    p r o c e d u r e P 2 .

    Co m p u t in g S u rv ey s , Vo l . 3 , No . 3 , S ep t em b er 1 9 71

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    14/32

    128 •

    H e n r y F . L e d g a r d

    Discussion

    T h e a b o v e t h r e e e x a m p l e s i l l u s t r a t e a n

    i m p o r t a n t f e a t u r e o f p r o g r a m m i n g l a n -

    g u a g e s : n a m e l y , t h e d i f fe r e n c e s i n t h r e e

    c o m m o n l y u s e d m e t h o d s o f p a s si n g p a r a m -

    e t e r s t o p r o c e d u r e s . T o e x p l a i n t h i s d i f f e r -

    e n c e , o n e m a y w e l l a s k : w h a t i s t h e " v a l u e "

    o f e a c h p r o c e d u r e ? F o l l o w i n g t h e i d e a s o f

    S t r a c h e y [1 6], w e c o n s i d e r t h e n o t i o n o f a

    " s t o r e . "

    A s t o r e i s a m a p p i n g o f l o c a t i o n s i n t o

    v a l u e s , w h e r e e a c h i d e n t i f i e r i n a p r o g r a m is

    c o n s i d e r e d t o h a v e a l o c a t i o n , a n d t h e v a l u e

    a s s o c i a t e d w i t h t h i s l o c a t i o n i n t h e s t o r e i s

    t a k e n a s t h e c u r r e n t v a l u e o f t h e i d e n t i f ie r .

    A p r o c e d u r e w i t h n p a r a m e t e r s m a y t h e n b e

    v i e w e d a s a fu n c t i o n m a p p i n g n a r g u m e n t s

    and a s tore

    i n t o a n e w s t o r e . A p r o c e d u r e

    c o m m a n d is v i e w e d a s a n a p p l i c a t io n o f t h e

    f u n c t i o n t o t h e a r g u m e n t s g i v e n i n t h e c o m -

    m a n d a n d t o t h e s t o r e o f v a l u e s e x i s t i n g b e -

    f o r e t h e c o m m a n d i s e x e c u t e d • T h e n e w ,

    r e t u r n e d s t o r e r e f l e c t s t h e c h a n g e i n v a l u e s

    o f t h e p r o g r a m i d e n t if i e rs .

    I n p a r t i c u l a r , l e t

    I D d e n o t e t h e s e t o f i d e n ti f ie r s f o r a p r o g r a m ;

    L O C d e n o t e t h e s e t of l o c a t i o n s a s s o c i a t e d

    w i t h t h e i d e n t i f i e r s i n I D ;

    V A L d e n o t e a s e t o f v a l u e s ( f o r m i n i - l a n-

    g u a g e 5 , V A L c o n s i s t s o n l y o f t h e n a t u r a l

    n u m b e r s ) ;

    E X P d e n o t e a s e t o f e x p re s s io n s ; a n d

    S T R d e n o t e a s e t o f s t o r e s, i .e ., f u n c t i o n s

    ( L O C ~ V A L ) m a p p i n g l o ca t io n s i n to

    v a l u e s .

    I f s is a s t o r e , v a v a lu e , a n d l a l o ca t i o n , l e t

    s[v/l]

    d e n o t e t h e s t o r e

    s'

    t h a t i s i d e n t i c a l t o

    s e x c e p t t h a t l i s m a p p e d i n t o v.

    T h e v a l u e o f p r o c e d u r e P 1 , w h o s e a r g u -

    m e n t s a r e c a l l e d b y c o p y v a lu e , i s t h e f u n c -

    t i o n :

    X ( v l ~ V A L , v 2 C V A L , s E S T R ) . s

    T h a t is, P 1 i s a f u n c t i o n t h a t , w h e n a p p l i e d

    to tw o v a lu e s , Vl an d v 2 , an d a s t o r e , s ,

    r e t u r n s t h e i d e n t i c a l s t o r e s . H e n c e P 1

    p r o d u c e s n o s w a p p i n g o f v a l u e s o n a s t o r e t o

    w h i c h i t i s a p p l i e d .

    T h e v a l u e o f t h e p r o c e d u r e P 2 , w h o s e

    a r g u m e n t s a r e c a l l e d b y l o c a t i o n , is t h e f un c -

    t i o n :

    X (/1E L O C , 1 2 E L O C , s E S T R )

    • s [ s ( l ~ ) / l l ] [ s ( l l ) / l ~ ]

    T h a t is , P 2 is a f u n c t i o n t h a t , w h e n a p p l ie d

    t o t w o l o c a t i o n s , l l a n d

    12,

    an d a s t o r e , s ,

    r e t u r n s a n e w s t o r e t h a t i s i d e n t i c a l t o s

    e x c e p t t h a t ll - o v 2 , w h e r e

    v2 = s(l~),

    an d

    12 - -~ Vl, w he re Vl = s(/1) , w hi ch is preci sely

    t h e d e s i r e d e f f e c t . I n p a r t i c u l a r , t h e p r o c e -

    d u r e c o m m a n d P 2 ( I , A [ I ] ) s w a p s t h e v a l u e s

    s t o r e d i n t h e l o c a t io n s r e s e r v e d f o r I a n d

    N I L

    T h e v a l u e o f t h e p r o c e d u r e P 3 , w h os e

    a r g u m e n t s a r e c a l l e d b y e x p r e s s io n is t he

    f u n c t i o n :

    X (elE E X P , e~E E X P , s E S T R ) •

    s[v2/ll][Vj/12']

    w h er e v~ i s t h e v a lu e o f e~ u s in g t h e s to r e o f

    v a l u e s i n s ; ll i s t h e l o c a t i o n d e n o t e d b y el

    u s i n g t h e s t o r e o f v a l u e s i n s ; s' i s t h e s t o re

    s[v2/ll]; Vl i s t h e v a l u e o f e l u s i n g t h e s t or e

    o f v a l u e s i n s ; a n d 12' i s t h e l o c a t i o n d e n o t e d

    b y e2 u s i n g t h e s t o r e o f v a l u e s i n s '. H e r e t h e

    l o c a t i o n 12' i s d e p e n d e n t o n t h e s t o r e s ' =

    s[v2/ll];

    i . e . , an y u s e o f e l ( u s ed i n o b t a in in g

    11) i n e2 ( u s ed i n o b t a in in g l ( ) m ay r e s u l t i n a

    di f ferent

    l o c a t i o n l~ ' f o r e2 f r o m t h a t ex i st -

    i n g b e f o r e t h e p r o c e d u r e i n v o c a t i o n .

    M I N I - L A N G U A G E 6 :

    S T A TIC T Y P E C H E C K I N G

    T h e p a r t i t i o n i n g o f o b j e c t s i n t o c l a s s e s o r

    " t y p e s " i s a p r o m i n e n t f e a t u r e o f m a n y

    p r o g r a m m i n g l a n g u a g e s • O f t e n , o p e r a t i o n s

    a r e d e f i n e d o n l y o v e r d a t a o f a c e r t a i n t y p e .

    T h i s g i v e s r is e t o a b a s i c q u e s t i o n : i s e a c h

    o p e r a t i o n i n a p r o g r a m d e f i n e d fo r t h e p a r ti c -

    u l a r d a t a e l e m e n t s i t i s g i v e n ? I f t h is q u e s t io n

    c a n b e a n s w e r e d

    before

    e x e c u t i o n o f a p r o -

    g r am ( a s , f o r ex am p le , i n F O R TR A N ), i t i s a

    c a s e o f s t a t i c t y p e c h e c k i n g • I f t h i s q u e s t i o n

    c a n o n l y b e a n s w e r e d

    d u r i n g

    e x e c u t i o n o f a

    p r o g r a m ( a s, f o r e x a m p l e , i n P A L o r GE DA N-

    K E N ) , w e

    h a v e a c a s e o f d y n a m i c t y p e c h e c k-

    i n g. I n s o m e l a n g u a g e s ( f o r e x a m p l e , A LG OL

    6 0 o r SN O B O L), t h i s q u e s t i o n c an b e an s w er ed

    Computing Surveys , Vol. 3 , No. 3 , September 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    15/32

    in p a r t b e f o r e e x e c u t i o n a n d in p a r t o n l y

    d u r i n g e x e c u t i o n .

    M i n i - l a n g u a g e 6 t r e a t s t h e c a s e o f s t a t i c

    t yp e c h e c k i n g , w i t h t h e i n t e n t t h a t a p r o -

    p o s e d p r o g r a m

    not

    b e e x e c u t e d u n l e s s a l l

    t yp e r e q u i r e m e n t s a r e s a t is f ie d . ( M i n i -

    l a n g u a g e 7 t r e a t s d y n a m i c t y p e c h e c k i n g . )

    Description of Lan gua ge Elements

    A t y p e d e s i g n a t i o n

    i s e i t h e r : 1 ) t h e s y m b o l

    N ,

    i n w h i c h c a s e i t d e n o t e s t h e c l a s s o f

    n a t u r al n u m b e r s ; o r 2 ) a s t r i n g o f t h e f o r m

    (t~, • • • , t~ --~ t~+~), w h e re th e t~, 1 ~ i ~4 n -~ 1,

    a re t y p e d e s i g n a t i o n s , i n w h i c h c a s e i t d e -

    n o te s a c l a s s o f f u n c t i o n s w h o s e d o m a i n i s

    th e C a r t e s i a n p r o d u c t o f th e c l a s s es d e n o t e d

    b y h , " ' " , t~ a n d w h o s e r a n g e i s t h e c l a ss

    d e n o t e d b y t ~ + ~ .

    P r i m i t i v e o b j e c t s

    i n m i n i - l a n g u a g e 6 i n -

    c l u d e , i n a d d i t i o n t o t h e n a t u r a l n u m b e r s ,

    a u n a r y f u n c t io n , S Q , f o r c o m p u t i n g t h e

    s q u a re o f a n a t u r a l n u m b e r , a n d a n i n fi x

    b i n ar y f u n c t i o n , + , f o r c o m p u t i n g th e s u m

    of t w o n a t u r a l n u m b e r s . T h e n a t u r a l n u m -

    b er s h a v e a t y p e N , a n d t h e f u n c t i o n s S Q

    a n d - / - h a v e t y p e s ( N - - ~ N ) a n d ( N , N - - ~ N ) .

    A d ec la ra t io n

    s p e c i f i e s a n

    i d en t i f i e r

    a s

    r e p r e s e n t i n g a c l a s s o f o b j e c t s o f o n l y o n e

    t y p e . * A d e c l a r a t i o n c o n s i s t s o f a s t r i n g o f

    e i t h e r o f t h e f o l l o w i n g f o r m s :

    1 ) d e c l t y p e t

    2 ) d e c f ( l ) : = e w h e r e I t

    w h e r e l i s a l i s t o f i d e n t i f i e r s , t a t y p e d e s i g -

    n a t io n , f a n i d e n t i f ie r , e a n e x p r e s s i o n ( d e -

    f i n e d b e l o w ) , a n d

    It

    i s a l is t o f t y p e d e s i g n a -

    t io n s s u c h t h a t e a c h i d e n t i f i e r i n 1 i s d i f f e r e n t ;

    e a ch id e n t i f i e r i n e o c c u r s i n l; a n d t h e n u m -

    b e r o f t y p e d e s i g n a t i o n s i n

    It

    i s i d e n t i c a l t o

    t h e n u m b e r o f i d e n t i f i e r s i n 1.

    A d e c l a r a t i o n o f f o r m ( 1) s p e c if ie s t h a t

    e a c h i d e n t i f i e r i n I h a s t h e t y p e t. A d e c l a r a -

    t io n o f f o r m ( 2) : a ) a s s i g n s t o f t h e f u n c t i o n

    f ro m a r g u m e n t s in t h e d o m a i n , d e n o t e d b y

    t~, • • . , t~ = It ,

    i n t o t h e v a l u e o f t h e e x p r e s -

    s i o n e , o b t a i n e d b y r e p l a c i n g e a c h i d e n t i f i e r

    in l b y i t s c o r r e s p o n d i n g a r g u m e n t ; a n d b )

    s pe cif ie s t h a t t h e t y p e o f f i s ( h , " " ,

    • N ote tha t th i s requi rem ent i s

    not

    made in

    mini- language 7, where the types of objects as-

    signed to identif iers m ay v ary .

    T e n M i n i - L a n g u a g e s •

    129

    tn

    - - ~ t n + l ) ,

    w he re t : , • • • , tn

    =

    It a r e t h e t y p e

    d e s i g n a t i o n s g i v e n i n t h e d e c l a r a t i o n o f f ,

    a n d tn +l i s t h e t y p e o f t h e r e s u l t e x p r e s s i o n e

    ( d e f i n e d b e l o w ) , o b t a i n e d b y u s i n g t h e t y p e s

    h , " . , t~ f o r t h e c o r r e s p o n d i n g i d e n ti f ie r s

    of l in e .

    A n

    e x p r e s s i o n

    c o n s i s t s o f a s t r i n g o f o n e o f

    t h e f o l lo w i n g f o r m s :

    1) p

    2) i

    3) SQ(e)

    ( p r o v i d e d e i s o f t y p e N )

    4) d+e)

    ( p r o v i d e d d a n d e a r e o f t y p e N )

    5)

    f ( e l , . . . , en)

    (p ro v i de d f i x o f t y p e (h , " " , tn ----~ n+~) ,

    a n d e ~, • • • , en a r e o f c o r r e s p o n d i n g t y p e

    t 2 , ' ' ' , t n )

    6 )

    ( i f

    d > e

    t h e n e l

    e l s e

    e2)

    ( p r o v i d e d d a n d e a r e o f ty p e N , a n d

    e l

    a n d e2 a r e o f t h e s a m e t y p e ) ,

    w h e r e p i s a p r i m i t i v e s y m b o l , i a n d f a r e

    i d e n t i f ie r s , a n d d , e , e , , . . . , e , a r e e x p r e s -

    s i o n s .

    E x p r e s s i o n s a r e o f t h e f o l l o w i n g t y p e s :

    1 ) a n e x p r e s s i o n o f f o r m ( 1) is o f t h e s a m e

    t y p e a s p ;

    2 ) a n e x p r e s s i o n o f f o r m (2 ) is o f th e t y p e

    d e c l a r e d f o r i ;

    3 ) i f e is of t y p e N , t h e n a n e x p r e s s i o n o f

    f o r m ( 3) is o f t y p e N ;

    4 ) i f d a n d e a r e o f t y p e N , a n e x p r e s s i o n o f

    f o r m ( 4) is o f t y p e N ;

    5 ) if t h e t y p e s o f e l , . . . , e~

    a r e

    t l , " ' ' ,

    t ~ , a n d i f f i s d e c l a r e d t o b e o f t y p e

    ( h , • • • tn - -~ t~+ l) , t h e n an ex pr es s io n o f

    f o r m ( 5 ) i s o f t y p e tn+ ~ ; a n d

    6 ) i f d , e a r e o f t y p e N , a n d e l , e2 a r e o f t h e

    s a m e t y p e , t h e n a n e x p r e s s io n o f f o r m (6 )

    i s o f t h e s a m e t y p e a s el o r e 2 .

    A n

    a s s i g n m e n t c o m m a n d

    c o n s i s t s o f a

    s t r i n g o f t h e f o r m i : = e , w h e r e i i s a n i d e n t i -

    f i e r , a n d e i s a n e x p r e s s i o n s u c h t h a t t h e

    t y p e s o f i a n d e m u s t b e id e n t i c a l.

    A p r o g r a m

    c o n s i s t s o f a s e q u e n c e d o f

    d e c l a r a t i o n s f o l l o w e d b y a s e q u e n c e c o f

    a s s i g n m e n t c o m m a n d s s u c h t h a t e a c h i d e n -

    t i f ie r o c c u r r i n g i n c i s d e c l a r e d o n c e a n d

    o n l y o n c e i n d , a n d

    al l

    o f t h e a b o v e r e q u i r e -

    m e n t s o n t y p e s a r e s a ti s fi e d .

    C o mp u t in g S u rv e y s , Vo l . 3 , No . 3 , S e p te mb e r 1 9 71

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    16/32

    130 • Hen ry F . Ledgard

    Prog ram Execution

    T h e c o m m a n d s o f a p r o g r a m a r e e x e c u t e d

    s e q u e n t i a ll y , w i t h t h e c o n v e n t i o n a l m e a n i n g

    f o r a d d i t i o n , t h e s q u a r i n g o p e r a t i o n , a s s i g n -

    m e n t , c o n d i t i o n a l e x p r e s s i o n s , a n d f u n c -

    t i o n a l a p p l i c a t i o n .

    EXAMPLE 1:

    d e c A , B t y p e N

    d e e F ( X ) : = 8 Q ( SQ ( X )) w h e r e N

    A : = 2

    B : = F ( A )

    E X A M P L E 2 :

    d e c X t y p e N

    d e e

    A, B t y p e (N----~N)

    d e c

    F ( X ) : = S Q ( S Q ( X ) )

    w h e r e

    N

    d e e G ( X , Y ) : = X ( Y ) w h e r e

    ( N - - I N ) , N

    A : = S Q

    B : = F

    X : = (G(A , 1 ) + G( B , 2 ) )

    EXAMP LE 3 ( s y n t a c t i c a l l y i l leg a l ) :

    d e e A , B . t y p e N

    d e e F ( X ) : = ( X + X ) w h e r e N

    d e e

    G ( X , Y ) : = i X + Y ) w h e r e N , N

    d e e H ( X , Y ) : = X ( Y ) w h e r e (N ---~ N), N

    A : = H ( F , 1 )

    B : = H ( G , l )

    EXAMPLE 4 ( s y n t a c t i c a l l y i l leg a l ) :

    d e e A t y p e

    N

    d e c B t y p e ( N ~ N )

    d e c F ( X ) : = X w h e r e N

    d e e G ( X ) : = X w h e r e ( N - + N )

    d e e H ( X , Y ) : = X ( Y ) w h e r e ((N--+N)---~

    (N~N)), (N~N)

    g : = H ( G , S Q )

    A : = B ( 2 )

    B : = H ( F , 2 )

    E x a m p l e 1 r e s u l t s i n s e t t i n g t h e v a l u e o f

    B t o 1 6 . E x a m p l e 2 r e s u l t s i n s e t t i n g t h e

    v a l u e o f X t o 1 7 .

    Ex am p l e 3 i s i l l eg a l b ecau s e o f t h e s t a t e -

    m e n t B : = H ( G , 1 ) , " w h e r e H , a f u n c t i o n

    o f t y p e ( (N - -~ N ) , N --~ X) , i s ap p l i ed t o

    a r g u m e n t s G , 1 o f t y p e s ( X , N - + X ) , X .

    U s i n g t h e r u l e s g i v e n p r e v i o u s l y , w e c a n

    d e t e r m i n e t h a t t h e p r o g r a m o f E x a m p l e 3

    i s s y n t a c t i c a l l y i l l e g a l :

    1 ) A a n d B a r e d e c l a r e d t o b e of t y p e N ;

    2 ) F i s dec la red to be o f type (N-- -aN) ;

    3 ) G is d e c l a r e d t o b e o f t y p e ( N , N ~ N ) ;

    4 ) H i s d e c l a r e d t o b e o f t y p e ( ( N - - i N ) ,

    N ---~ N ) ;

    5 ) H (F , 1 ), w h e re F , 1 a r e o f t y p es (N --~N ) ,

    N an d H is of ty p e ((N---- iN), N --~ N ),

    is o f t y p e N ;

    6 ) A : = H ( F , 1 ) i s t y p e - w i s e o f t h e f o r m

    N : = N , h e n c e i s t y p e - w i s e c o r r e c t;

    t h e r e f o r e ,

    7 ) H(G , 1 ) , wh e re G , 1 a r e o f t y p es (N ,

    N --~N) , N an d H i s o f ty p e ( (N--~N) ,

    N -+ N ) , i s i l leg a l b ecau s e t h e t y p e

    (N , N - -~ N ) o f G i s n o t i d en t i c a l t o t h e

    t y p e ( N -- + N ) o f t h e f i r s t a r g u m e n t o f H .

    Ex am p l e 4 i s i l l eg a l b ecau s e o f t i l e s t a t e -

    m e n t " B : = H ( F , 2 ) , " w h e r e H , a f u n c ti o n

    of ty p e (((N--)N)---~(N--~N)), (N--~N )

    ( N - - + N ) ) , i s a p p l i e d t o a r g u m e n t s F a n d 2

    o f t y p e s ( N - -+ N ) a n d N . N o t e , h o w e v e r ,

    t h a t t h e a p p l i c a t i o n o f H t o F a n d 2 is

    s em an t i ca l l y we l l -d e f i n ed , i . e . , r e s u l t s i n

    a p p l y i n g F t o 2 , w h i c h r e t u r n s t h e v a l u e 2 .

    ( P r o g r a m s l i k e t h a t o f E x a m p l e 4 w i l l b e

    a l l o wed i n m i n i - l an g u ag e 7 . ) N o t e , a l s o ,

    t h a t i n a l l s y n t a c t i c a l l y l eg a l p r o g r a m s i n

    m i n i - l a n g u a g e 6 , n o c o n d i t i o n l e a d i n g t o a

    t y p e e r r o r c a n a r i s e d u r i n g e x e c u t i o n .

    Discussion

    I n m i n i - l a n g u a g e 6 , t h e r e w e r e f o u r m a j o r

    a s s u m p t i o n s u n d e r l y i n g t h e n o t i o n s o f ty p e s .

    ( T h e r e a d e r i s r e f e r r e d t o t h e w o r k o f M o r r is

    [1 1] fo r a d i s cu s s i o n o f t y p es a n d t y p e ch eck -

    ing . )

    Assumpt ion 1

    A t y p e i s e i t h e r a n a t o m i c t y p e , i n w h i c h

    cas e i t d en o t e s a c l a s s o f p r i m i t i v e o b j ec t s ,

    o r it, i s a f u n c t i o n a l t y p e ( h , " - , t ,

    t~ + l) , wh e re h , " " , t , ,, t , + l a r e t y p e s , i n

    wh i ch ca s e i t d en o t e s a c l a s s o f fu n c t i o n s .

    A s s um p t ion 2

    T h e n u m b e r o f a t o m i c t y p e s i s f i n i t e .

    A s s u m p t i o n s 1 a n d 2 s e e m i n t u i t i v e , b u t

    t h e y d o r a i s e s o m e i m p o r t a n t q u e s t i o n s :

    n o t a b l y , w h a t a r e t h e a t o m i c t y p e s f o r o u r

    u n i v e r s e o f d i s c o u r s e ? W e r e a d i l y a c c e p t

    Co m putin g Surveys , V ol . 3 , No. 3 , September 1971

  • 8/9/2019 Ten Mini-Languages: a Study of Topical Issues in Programming Languages

    17/32

    p o i n t e r s , i n t eg e r s , r a t i o n a l s , B o o l ean s , an d

    s t r i n g s a s d e n o t i n g a t o m i c t y p e s . B u t w h a t

    a b o u t l a b e l s , l o c a t i o n s , P L / I s t o r a g e c l a s s

    a t t r i b u t e s ( a u t o m a t i c o r s t a t i c ) , a n d P L / I

    f il e a t t r i b u t e s ( b u f f e r e d o r u n b u f f e r e d ) ?

    Are t h e s e l an g u ag e i s s u es t o b e co n s i d e red a s

    p a r t o f type c o n s i d e r a t i o n s ? C o n s i d e r , f o r

    e x a m p l e , a n a s s i g n m e n t s t a t e m e n t o f t h e

    f o rm e l : = e 2 . A s p a r t o f o u r t y p e c h e c k i n g

    w e u s u a l l y w a n t t o e n s u r e t h a t e~ a n d e2

    a r e b o t h n u m e r i c o r b o t h B o o l e a n . M i g h t

    w e a l so w a n t t o e n s u r e t h a t e l d e n o t e s a

    l o ca t i o n an d e2 a v a l u e , s o a s t o i n c l u d e , s ay ,

    ( if X > Y t h e n I e l se J)

    : = ( i f A > B t h e n 1 e l se 2)

    b u t ex c l u d e

    (i f A > B t h e n 1 e l s e 2)

    : = ( i f X > Y