Practical Foundations for Programming Languages

Total Page:16

File Type:pdf, Size:1020Kb

Practical Foundations for Programming Languages Practical Foundations for Programming Languages Robert Harper Carnegie Mellon University [Version 1.32 of 05.15.2012.] Copyright c 2012 by Robert Harper. All Rights Reserved. The electronic version of this work is licensed under the Cre- ative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Preface Types are the central organizing principle of the theory of programming languages. Language features are manifestations of type structure. The syntax of a language is governed by the constructs that define its types, and its semantics is determined by the interactions among those constructs. The soundness of a language design—the absence of ill-defined programs— follows naturally. The purpose of this book is to explain this remark. A variety of pro- gramming language features are analyzed in the unifying framework of type theory. A language feature is defined by its statics, the rules govern- ing the use of the feature in a program, and its dynamics, the rules defining how programs using this feature are to be executed. The concept of safety emerges as the coherence of the statics and the dynamics of a language. In this way we establish a foundation for the study of programming languages. But why these particular methods? The main justification is provided by the book itself. The methods we use are both precise and in- tuitive, providing a uniform framework for explaining programming lan- guage concepts. Importantly, these methods scale to a wide range of pro- gramming language concepts, supporting rigorous analysis of their prop- erties. Although it would require another book in itself to justify this as- sertion, these methods are also practical in that they are directly applicable to implementation and uniquely effective as a basis for mechanized reasoning. No other framework offers as much. Being a consolidation and distillation of decades of research, this book does not provide an exhaustive account of the history of the ideas that in- form it. Suffice it to say that much of the development is not original, but rather is largely a reformulation of what has gone before. The notes at the end of each chapter signpost the major developments, but are not intended as a complete guide to the literature. For further information and alterna- tive perspectives, the reader is referred to such excellent sources as Con- stable(1986), Constable(1998), Girard(1989), Martin-L of¨ (1984), Mitchell (1996), Pierce(2002, 2004), and Reynolds(1998). The book is divided into parts that are, in the main, independent of one another. Parts I and II, however, provide the foundation for the rest of the book, and must therefore be considered prior to all other parts. On first reading it may be best to skim Part I, and begin in earnest with Part II, returning to Part I for clarification of the logical framework in which the rest of the book is cast. Numerous people have read and commented on earlier editions of this book, and have suggested corrections and improvements to it. I am particu- larly grateful to Andrew Appel, Iliano Cervesato, Lin Chase, Derek Dreyer, Zhong Shao, and Todd Wilson for their extensive efforts in reading and criticizing the book. I also thank the following people for their sugges- tions: Arbob Ahmad, Zena Ariola, Eric Bergstrome, Guy Blelloch, William Byrd, Luis Caires, Luca Cardelli, Manuel Chakravarty, Richard C. Cobbe, Karl Crary, Yi Dai, Daniel Dantas, Anupam Datta, Jake Donham, Favonia, Matthias Felleisen, Kathleen Fisher, Dan Friedman, Peter Gammie, Maia Ginsburg, Byron Hawkins, Kevin Hely, Justin Hsu, Cao Jing, Salil Joshi, Gabriele Keller, Scott Kilpatrick, Danielle Kramer, Dan Kreysa, Akiva Lef- fert, Ruy Ley-Wild, Dan Licata, Karen Liu, Dave MacQueen, Chris Martens, Greg Morrisett, Tom Murphy, Aleksandar Nanevski, Georg Neis, David Neville, Doug Perkins, Frank Pfenning, Jean Pichon, Benjamin Pierce, An- drew M. Pitts, Gordon Plotkin, David Renshaw, John Reynolds, Carter Schonwald, Dale Schumacher, Dana Scott, Robert Simmons, Pawel Sobocin- ski, Daniel Spoonhower, Paulo Tanimoto, Peter Thiemann, Bernardo Ton- inho, Michael Tschantz, Kami Vaniea, Carsten Varming, David Walker, Dan Wang, Jack Wileden, Roger Wolff, Omer Zach, Luke Zarko, Yu Zhang. I am grateful to the students of 15–312 and 15–814 at Carnegie Mellon who have provided the impetus for the preparation of this book and who have en- dured the many revisions to it over the last ten years. I thank the Max Planck Institute for Software Systems in Germany for its hospitality and support. I also thank Espresso a Mano in Pittsburgh, CB2 Cafe in Cambridge, and Thonet Cafe in Saarbrucken¨ for providing a steady supply of coffee and a conducive atmosphere for writing. This material is, in part, based on work supported by the National Sci- ence Foundation under Grant Nos. 0702381 and 0716469. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation. Robert Harper Pittsburgh March, 2012 Contents Preface iii I Judgments and Rules1 1 Syntactic Objects3 1.1 Abstract Syntax Trees.......................4 1.2 Abstract Binding Trees......................7 1.3 Notes................................ 12 2 Inductive Definitions 15 2.1 Judgments............................. 15 2.2 Inference Rules.......................... 16 2.3 Derivations............................. 17 2.4 Rule Induction........................... 19 2.5 Iterated and Simultaneous Inductive Definitions....... 21 2.6 Defining Functions by Rules................... 22 2.7 Modes............................... 24 2.8 Notes................................ 25 3 Hypothetical and General Judgments 27 3.1 Hypothetical Judgments..................... 27 3.1.1 Derivability........................ 27 3.1.2 Admissibility....................... 29 3.2 Hypothetical Inductive Definitions............... 31 3.3 General Judgments........................ 33 3.4 Generic Inductive Definitions.................. 34 3.5 Notes................................ 36 viii CONTENTS II Statics and Dynamics 37 4 Statics 39 4.1 Syntax............................... 39 4.2 Type System............................ 40 4.3 Structural Properties....................... 42 4.4 Notes................................ 44 5 Dynamics 45 5.1 Transition Systems........................ 45 5.2 Structural Dynamics....................... 47 5.3 Contextual Dynamics....................... 49 5.4 Equational Dynamics....................... 51 5.5 Notes................................ 54 6 Type Safety 55 6.1 Preservation............................ 56 6.2 Progress.............................. 56 6.3 Run-Time Errors.......................... 58 6.4 Notes................................ 59 7 Evaluation Dynamics 61 7.1 Evaluation Dynamics....................... 61 7.2 Relating Structural and Evaluation Dynamics......... 63 7.3 Type Safety, Revisited....................... 64 7.4 Cost Dynamics.......................... 65 7.5 Notes................................ 66 III Function Types 67 8 Function Definitions and Values 69 8.1 First-Order Functions....................... 70 8.2 Higher-Order Functions..................... 71 8.3 Evaluation Dynamics and Definitional Equality....... 73 8.4 Dynamic Scope.......................... 74 8.5 Notes................................ 76 VERSION 1.32 REVISED 05.15.2012 CONTENTS ix 9 G¨odel’s T 77 9.1 Statics................................ 78 9.2 Dynamics............................. 79 9.3 Definability............................ 80 9.4 Undefinability........................... 82 9.5 Notes................................ 84 10 Plotkin’s PCF 85 10.1 Statics................................ 87 10.2 Dynamics............................. 88 10.3 Definability............................ 90 10.4 Notes................................ 92 IV Finite Data Types 93 11 Product Types 95 11.1 Nullary and Binary Products.................. 96 11.2 Finite Products.......................... 97 11.3 Primitive and Mutual Recursion................ 98 11.4 Notes................................ 100 12 Sum Types 101 12.1 Nullary and Binary Sums.................... 101 12.2 Finite Sums............................ 103 12.3 Applications of Sum Types.................... 104 12.3.1 Void and Unit....................... 104 12.3.2 Booleans.......................... 105 12.3.3 Enumerations....................... 106 12.3.4 Options.......................... 106 12.4 Notes................................ 108 13 Pattern Matching 109 13.1 A Pattern Language........................ 110 13.2 Statics................................ 110 13.3 Dynamics............................. 112 13.4 Exhaustiveness and Redundancy................ 114 13.4.1 Match Constraints.................... 114 13.4.2 Enforcing Exhaustiveness and Redundancy...... 116 13.4.3 Checking Exhaustiveness and Redundancy...... 117 REVISED 05.15.2012 VERSION 1.32 x CONTENTS 13.5 Notes................................ 119 14 Generic Programming 121 14.1 Introduction............................ 121 14.2 Type Operators.......................... 122 14.3 Generic Extension......................... 122 14.4 Notes................................ 125 V Infinite Data Types 127 15 Inductive and Co-Inductive Types 129 15.1 Motivating Examples....................... 129 15.2 Statics...............................
Recommended publications
  • Typology of Programming Languages E Early Languages E
    Typology of programming languages e Early Languages E Typology of programming languages Early Languages 1 / 71 The Tower of Babel Typology of programming languages Early Languages 2 / 71 Table of Contents 1 Fortran 2 ALGOL 3 COBOL 4 The second wave 5 The finale Typology of programming languages Early Languages 3 / 71 IBM Mathematical Formula Translator system Fortran I, 1954-1956, IBM 704, a team led by John Backus. Typology of programming languages Early Languages 4 / 71 IBM 704 (1956) Typology of programming languages Early Languages 5 / 71 IBM Mathematical Formula Translator system The main goal is user satisfaction (economical interest) rather than academic. Compiled language. a single data structure : arrays comments arithmetics expressions DO loops subprograms and functions I/O machine independence Typology of programming languages Early Languages 6 / 71 FORTRAN’s success Because: programmers productivity easy to learn by IBM the audience was mainly scientific simplifications (e.g., I/O) Typology of programming languages Early Languages 7 / 71 FORTRAN I C FIND THE MEAN OF N NUMBERS AND THE NUMBER OF C VALUES GREATER THAN IT DIMENSION A(99) REAL MEAN READ(1,5)N 5 FORMAT(I2) READ(1,10)(A(I),I=1,N) 10 FORMAT(6F10.5) SUM=0.0 DO 15 I=1,N 15 SUM=SUM+A(I) MEAN=SUM/FLOAT(N) NUMBER=0 DO 20 I=1,N IF (A(I) .LE. MEAN) GOTO 20 NUMBER=NUMBER+1 20 CONTINUE WRITE (2,25) MEAN,NUMBER 25 FORMAT(11H MEAN = ,F10.5,5X,21H NUMBER SUP = ,I5) STOP TypologyEND of programming languages Early Languages 8 / 71 Fortran on Cards Typology of programming languages Early Languages 9 / 71 Fortrans Typology of programming languages Early Languages 10 / 71 Table of Contents 1 Fortran 2 ALGOL 3 COBOL 4 The second wave 5 The finale Typology of programming languages Early Languages 11 / 71 ALGOL, Demon Star, Beta Persei, 26 Persei Typology of programming languages Early Languages 12 / 71 ALGOL 58 Originally, IAL, International Algebraic Language.
    [Show full text]
  • A Politico-Social History of Algolt (With a Chronology in the Form of a Log Book)
    A Politico-Social History of Algolt (With a Chronology in the Form of a Log Book) R. w. BEMER Introduction This is an admittedly fragmentary chronicle of events in the develop­ ment of the algorithmic language ALGOL. Nevertheless, it seems perti­ nent, while we await the advent of a technical and conceptual history, to outline the matrix of forces which shaped that history in a political and social sense. Perhaps the author's role is only that of recorder of visible events, rather than the complex interplay of ideas which have made ALGOL the force it is in the computational world. It is true, as Professor Ershov stated in his review of a draft of the present work, that "the reading of this history, rich in curious details, nevertheless does not enable the beginner to understand why ALGOL, with a history that would seem more disappointing than triumphant, changed the face of current programming". I can only state that the time scale and my own lesser competence do not allow the tracing of conceptual development in requisite detail. Books are sure to follow in this area, particularly one by Knuth. A further defect in the present work is the relatively lesser availability of European input to the log, although I could claim better access than many in the U.S.A. This is regrettable in view of the relatively stronger support given to ALGOL in Europe. Perhaps this calmer acceptance had the effect of reducing the number of significant entries for a log such as this. Following a brief view of the pattern of events come the entries of the chronology, or log, numbered for reference in the text.
    [Show full text]
  • Standards for Computer Aided Manufacturing
    //? VCr ~ / Ct & AFML-TR-77-145 )R^ yc ' )f f.3 Standards for Computer Aided Manufacturing Office of Developmental Automation and Control Technology Institute for Computer Sciences and Technology National Bureau of Standards Washington, D.C. 20234 January 1977 Final Technical Report, March— December 1977 Distribution limited to U.S. Government agencies only; Test and Evaluation Data; Statement applied November 1976. Other requests for this document must be referred to AFML/LTC, Wright-Patterson AFB, Ohio 45433 Manufacturing Technology Division Air Force Materials Laboratory Wright-Patterson Air Force Base, Ohio 45433 . NOTICES When Government drawings, specifications, or other data are used for any purpose other than in connection with a definitely related Government procurement opera- tion, the United States Government thereby incurs no responsibility nor any obligation whatsoever; and the fact that the Government may have formulated, furnished, or in any way supplied the said drawing, specification, or other data, is not to be regarded by implication or otherwise as in any manner licensing the holder or any person or corporation, or conveying any rights or permission to manufacture, use, or sell any patented invention that may in any way be related thereto Copies of this report should not be returned unless return is required by security considerations, contractual obligations, or notice on a specified document This final report was submitted by the National Bureau of Standards under military interdepartmental procurement request FY1457-76 -00369 , "Manufacturing Methods Project on Standards for Computer Aided Manufacturing." This technical report has been reviewed and is approved for publication. FOR THE COMMANDER: DtiWJNlb L.
    [Show full text]
  • Evolution of the Major Programming Languages
    COS 301 Programming Languages Evolution of the Major Programming Languages UMaine School of Computing and Information Science COS 301 - 2018 Topics Zuse’s Plankalkül Minimal Hardware Programming: Pseudocodes The IBM 704 and Fortran Functional Programming: LISP ALGOL 60 COBOL BASIC PL/I APL and SNOBOL SIMULA 67 Orthogonal Design: ALGOL 68 UMaine School of Computing and Information Science COS 301 - 2018 Topics (continued) Some Early Descendants of the ALGOLs Prolog Ada Object-Oriented Programming: Smalltalk Combining Imperative and Object-Oriented Features: C++ Imperative-Based Object-Oriented Language: Java Scripting Languages A C-Based Language for the New Millennium: C# Markup/Programming Hybrid Languages UMaine School of Computing and Information Science COS 301 - 2018 Genealogy of Common Languages UMaine School of Computing and Information Science COS 301 - 2018 Alternate View UMaine School of Computing and Information Science COS 301 - 2018 Zuse’s Plankalkül • Designed in 1945 • For computers based on electromechanical relays • Not published until 1972, implemented in 2000 [Rojas et al.] • Advanced data structures: – Two’s complement integers, floating point with hidden bit, arrays, records – Basic data type: arrays, tuples of arrays • Included algorithms for playing chess • Odd: 2D language • Functions, but no recursion • Loops (“while”) and guarded conditionals [Dijkstra, 1975] UMaine School of Computing and Information Science COS 301 - 2018 Plankalkül Syntax • 3 lines for a statement: – Operation – Subscripts – Types • An assignment
    [Show full text]
  • ALGOL 60 Programming on the Decsystem 10.Pdf
    La Trobe University DEPARTMENT OF MATHEMATICS ALGOL 60 Programming on the DECSystem 10 David Woodhouse Revised, August 1975 MELBOURNE, AUSTRALIA ALGOL 60 Programming on the DECSystem 10 David Woodhouse Revised, August 1975 CE) David Woodhouse National Library of Australia card number and ISBN. ISBN 0 85816 066 8 INTRODUCTION This text is intended as a complete primer on ALGOL 60 programming. It refers specifically to Version 4 of the DECSystem 10 implementation. However, it avoids idiosyncracies as far as possible, and so should be useful in learning the language on other machines. The few features in the DEC ALGOL manual which are not mentioned here should not be needed until the student is sufficiently advanced to be using this text for reference only. Exercises at the end of each chapter illustrate the concepts introduced therein, and full solutions are given. I should like to thank Mrs. K. Martin and Mrs. M. Wallis for their patient and careful typing. D. Woodhouse, February, 1975. CONTENTS Chapter 1 : High-level languages 1 Chapter 2: Languagt! struct.ure c.f ALGOL 6n 3 Chapter 3: Statemp.nts: the se'1tences {'\f the language 11 Chapter 4: 3tandard functions 19 Chapter 5: Input an~ Outp~t 21 Chapter 6: l>rray~ 31 Chapter 7 : For ane! ~hil~ statements 34 Chapter 8: Blocks anr! ',: ock sc rll,~ turr. 38 Chapter 9: PrOCe(:l1-:-~S 42 Chapter 10: Strin2 vp·jaLlps 60 Chapter 11: Own v~rj;lI'.i..es clOd s~itc.hef, 64 Chapter 12: Running ~nd ,;ebllggi"1g 67 Bibliography 70 Solutions to Exercises 71 Appendix 1 : Backus NOlUlaj F\:q'm 86 Appendix 2 : ALGuL-like languages 88 Appenclix 3.
    [Show full text]
  • Trends in Programming Language Design Professor Alfred V
    Trends in Programming Language Design Professor Alfred V. Aho Department of Computer Science Overview Columbia University – The most influential languages Trends in – Trends in language design Programming Language Design – Design issues in the AWK programming language 16 October 2002 1 Al Aho 2 Al Aho The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time • Assembler • Fortran – 1950s – 1950s – Step up from machine language – Created by a team led by John Backus of IBM – Available on virtually every machine – Initial focus: scientific computing – Influenced FI, FII, FIV, F77, F90, HPF, F95 3 Al Aho 4 Al Aho The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time • Cobol • Lisp – 1950s – 1950s – Created by U.S. DOD – Created by John McCarthy – Grace Murray Hopper influential in initial – Initial focus: symbol processing development – Influenced Scheme, Common Lisp, MacLisp, – Initial focus: business data processing Interlisp – Influenced C68, C74, C85, PL/1 – Dominant language for programming AI applications – The world’s most popular programming language for many years until the early 1990s 5 Al Aho 6 Al Aho The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time • Algol 60 • Basic – 1960 – Early 1960s – Algol 60 Report introduced BNF as a notation for – Created by John Kemeny and Thomaz Kurtz of describing the syntax of a language Dartmouth – Initial focus: general purpose programming – Initial focus: a simple, easy-to-use imperative – First block-structured language language – Influenced Algol 68, Pascal, Modula, Modula 2, – Influenced dozens of dialects, most notably Visual Oberon, Modula 3 Basic, probably the world’s most popular – Revised Algol 60 Report: P.
    [Show full text]
  • A View of the Origins and Development of Prolog
    ARTICLES A VIEW OF THE ORIGINS AND DEVELOPMENT OF PROLOG Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You’ve solved the wrong problem. Work hard to improve. (UNIX “fortune” message aptly describing Prolog’s sequential search mechanism in finding all solutions to ,a query) JACQUES COHEN The birth of logic programming can be viewed as the tives of the significant work done in the described confluence of two different research endeavors: one in areas. This review contrasts and complements these artificial or natural language processing, and the other two references by providing the background and moti- in automatic theorem proving. It is fair to say that both vation that led to the development of Prolog as a pro- these endeavors contributed to the genesis of Prolog. gramming language. Alain Colmerauer’s contribution stemmed mainly from The underlying thesis is that even seemingly abstract his interest in language processing, whereas Robert Ko- and original computer languages are discovered rather walski’s originated in his expertise in logic and theorem than invented. This by no means diminishes t:he formi- proving. (See [26] and the following article.) dable feat involved in discovering a language. It is This paper explores the origins of Prolog based on tempting to paraphrase the path to discovery in terms views rising mainly from the language processing per- of Prolog’s own search mechanism: One has to combine spective. With this intent we first describe the related the foresight needed to avoid blind alleys with the aes- research efforts and their significant computer litera- thetic sense required to achieve the simplest and most ture in the mid-1960s.
    [Show full text]
  • An Annotated Bibliography on Software Architecture
    'CGTM 13A Septemb€'r 1972 A~ A~~CTATEr BIELIOGRAPHY MASTER COP~ C~ 50F;WAR£ ~RCHltECTURE ,DO_NOT REMOVE "illiam E. Fiddle Stanford Iin€ar Accelerat6r Center Cowputaticn Group starford, California A1:stract. In the last fivE years research has been actively carried cut in an attempt to find structuring principles for large scftwat€ systems, d~si9n principles and methodologi~s fel such systems, and tecbniqups and mecha~isms for their efficient and economical irrplpmp.ntrttion. 1his interest has been generated by the hope of overcoming the protlEls stemming fre. the in~erent ccmflp.xity of large soft~at:e systems. This report proposes the name "software architecture" for this research area, ;ustifies net using the name "softw~re enginepcing" which i~ currently in vogue, overviews the .-........ content of the area, and presents a keyvorded and annot~t~d hibliography of the literature CD software architectur0. problems and their solution. I. Intro0uction architecture: the art Ot science of building; specif: the art or practice of designing and building structures, esp. habitable structures, in accordance with ~rinciples determined by aesth~tic dnd practical or material consider at ions. We~ster's Third New International Dictionary, Unabridged. "erriam Conrany, Springfield, Mass., 1964 During thE.' threp decade history of digital computers, there has heen a natural and grad ua 1 generalization of the research interests of computpr scientists. Initial software research was directed ~)rimarily toward the deterll'ination of fast, accurate alqorithms for Idlmt"'rical cornputati.on and efficient heuristics for non-numerical I This work was supported ty the Atc~ic Energy Comaission, Ptoject S u- 126P 23.
    [Show full text]
  • International Standard ISO/IEC 14977
    ISO/IEC 14977 : 1996(E) Contents Page Foreword ................................................ iii Introduction .............................................. iv 1Scope:::::::::::::::::::::::::::::::::::::::::::::: 1 2 Normative references :::::::::::::::::::::::::::::::::: 1 3 Definitions :::::::::::::::::::::::::::::::::::::::::: 1 4 The form of each syntactic element of Extended BNF :::::::::: 1 4.1 General........................................... 2 4.2 Syntax............................................ 2 4.3 Syntax-rule........................................ 2 4.4 Definitions-list...................................... 2 4.5 Single-definition . 2 4.6 Syntactic-term...................................... 2 4.7 Syntacticexception.................................. 2 4.8 Syntactic-factor..................................... 2 4.9 Integer............................................ 2 4.10 Syntactic-primary.................................... 2 4.11 Optional-sequence................................... 3 4.12 Repeatedsequence................................... 3 4.13 Grouped sequence . 3 4.14 Meta-identifier...................................... 3 4.15 Meta-identifier-character............................... 3 4.16 Terminal-string...................................... 3 4.17 First-terminal-character................................ 3 4.18 Second-terminal-character . 3 4.19 Special-sequence.................................... 3 4.20 Special-sequence-character............................. 3 4.21 Empty-sequence....................................
    [Show full text]
  • The Algol Family and ML Lisp Algol 60
    CS 242 Language Sequence The Algol Family and ML Lisp Algol 60 Algol 68 John Mitchell Pascal ML Modula Many other languages: Reading: Chapter 5 Algol 58, Algol W, Euclid, EL1, Mesa (PARC), … Modula-2, Oberon, Modula-3 (DEC) Algol 60 Algol 60 Sample Basic Language of 1960 real procedure average(A,n); • Simple imperative language + functions real array A; integer n; no array bounds • Successful syntax, BNF -- used by many successors begin – statement oriented – Begin … End blocks (like C { … } ) real sum; sum := 0; – if … then … else for i = 1 step 1 until n do • Recursive functions and stack storage allocation sum := sum + A[i]; • Fewer ad hoc restrictions than Fortran average := sum/n no ; here – General array references: A[ x + B[3]*y] end; • Type discipline was improved by later languages • Very influential but not widely used in US set procedure return value by assignment Algol oddity Some trouble spots in Algol 60 Question Type discipline improved by later languages • Is x := x equivalent to doing nothing? • parameter types can be array Interesting answer in Algol – no array bounds integer procedure p; • parameter type can be procedure – no argument or return types for procedure parameter begin …. Parameter passing methods p := p • Pass-by-name had various anomalies – “Copy rule” based on substitution, interacts with side effects …. • Pass-by-value expensive for arrays end; • Assignment here is actually a recursive call Some awkward control issues • goto out of block requires memory management 1 Algol 60 Pass-by-name Algol 68 Substitute text of actual parameter Considered difficult to understand • Unpredictable with side effects! • Idiosyncratic terminology Example – types were called “modes” – arrays were called “multiple values” procedure inc2(i, j); • vW grammars instead of BNF integer i, j; – context-sensitive grammar invented by A.
    [Show full text]
  • Algol and Pascal Constructs by R
    g Topic IV g Block-structured procedural languages Chapter 5 of Programming languages: Concepts & Algol and Pascal constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Chapter 7 of Understanding programming languages by Chapters 5 and 7, of Concepts in programming M Ben-Ari. Wiley, 1996. languages by J. C. Mitchell. CUP, 2003. Chapters 10(x2) and 11(x1) of Programming languages: Design and implementation (3RD EDITION) by T. W. Pratt and M. V. Zelkowitz. Prentice Hall, 1999. / 1 / 2 /. -, ()Parameters*+ position: There are two concepts that must be clearly distinguished: procedure Proc(First: Integer; Second: Character); A formal parameter is a declaration that appears in the Proc(24,'h'); declaration of the subprogram. (The computation in the In Ada it is possible to use named association in the call: body of the subprogram is written in terms of formal parameters.) Proc(Second => 'h', First => 24); An actual parameter is a value that the calling program ? What about in ML? Can it be simulated? sends to the subprogram. This is commonly used together with default parameters: Example: Named parameter associations. procedure Proc(First: Integer := 0; Second: Character := '*'); Normally the actual parameters in a subprogram call are just Proc(Second => 'o'); listed and the matching with the formal parameters is done by / 3 / 4 Named associations and default parameters are commonly used in /. -, the command languages of operating systems, where each ()Parameter passing*+ command may have dozens of options and normally only a few The way that actual parameters are evaluated and passed to parameters need to be explicitly changed.
    [Show full text]
  • Report on the Algorithmic Language ALGOL 60
    Reprinted from the COMMUNICATIONS OF THE ASSOCIATION FOR COMPUTING MACHINERY Vol. 3, No.5, May 1960 Made in U.S.A. With tYPographical corrections as of June ~8, 1980 Report on the Algorithmic Language ALGOL 60 PETER NAUR (Editor) J. W. BACKUS C. KATZ H. RUTISHAUSER J. H. WEGSTEIN F.L.BAUER J. MCCARTHY K. SAMELSON A. VAN WIJNGAARDEN J. GREEN A. J. PERLIS B. VAUQUOIS M. WOODGER Dedicated to the Memory of WILLIAM TURANSKI INTRODUCTION Background Meanwhile, in the United States, anyone who wished to After the publication of a preliminary report on the suggest changes or corrections to ALGOL was requested to send his comments to the ACM Communications where algorithmic language ALGOL,!' 2 as prepared at a conference in Zurich in 1958, much interest in the ALGOL language they were published. These comments then became the developed. basis of consideration for changes in the ALGOL language. As a result of an informal meeting held at Mainz in Both the SHARE and USE organizations established November 1958, about forty interested persons from ALGOL working groups, and both organizations were several European countries held an ALGOL implementation represented on the ACM Committee on Programming conference in Copenhagen in February 1959. A "hardware Languages. The ACM Committee met in Washington in group" was formed for working cooperatively right down November 1959 and considered all comments on ALGOL to the level of the paper tape code. This conference also that had been sent to the ACM Communications. Also, led to the publication by Regnecentralen, Copenhagen, of seven representatives were selected to attend the January an ALGOL Bulletin, edited by Peter Naur, which served 1960 international conference.
    [Show full text]