
Programming in Modula-3 Springer Berlin Heidelberg New York Barcelona Budapest Hong Kong London Milan Paris Santa Clara Singapore Tokyo Laszlo Boszormenyi Carsten Weich Programming in Modula-3 An Introduction in Programming with Style Foreword by Joseph Weizenbaum , Springer Usz16 Boszormenyi Carsten Weich U niversitat Klagenfurt Institutfiir Informatik UniversitatsstraBe 65-67 A-9022 Klagenfurt With 61 figures The software environment was created with the kind support of Springer­ Verlag, Digital Equipment Corporation, and Raiffeisenverband Karnten Translated from the German edition Programmieren mit Modula-3 by Robert Bach, Traunkirchen, Austria ISBN-13: 978-3-642-64614-0 e-ISBN-13: 978-3-642-60940-4 DOl: 10.1007/978-3-642-60940-4 CIP-data applied for Die Deutsche Bibliothek CIP-Einheitsaufnahme programming in Modula-3: an introduction in programming with style / Uszl6 Boszormenyi; Carsten Weich. Foreword by Joseph Weizenbaum [Trans!. from the German ed. by Robert Bach J. - Berlin; Heidelberg; New York; Barcelona; Budapest; Hong Kong; London; Milan; Paris; Santa Clara; Signapore; Tokyo: Springer; 1996 Dt. Ausg. u.d.T.: Boszormenyi. Uszl6: Programmieren mit Modula-3 ISBN-13: 978-3-642-64614-0 NE: Weich. Carsten: This work is subject to copyright. All rights are reserved. whether the whole or part of the material is concerned. specifically the rights oftranslation. reprinting. reuse ofillustrations. recitation. broadcasting. reproduction on microfilm or in other ways. and storage in data banks. Duplication ofthis publication or parts thereofis permiuedonlyunder the provisions of the German Copyright Law of September 9.1965. in its current version. and permission for use must always be obtained from Springer-Verlag. Violations are liable for prosecution act under German Copyright Law. © Springer-Verlag Berlin Heidelberg 1996 Softcover reprint ofthe hardcover 1st edition 1996 The use ofgeneral descriptive names. registered names. trademarks. etc. in this publication does not imply. even in the absence of a specific statement. that such names are exempt from the relevant protective laws and regulations and therefore free for general use. Typesetting: Camera-ready by authors; Cover illustration: Hegedus Miklos Cover design: Klinkel + Lopka Werbeagentur. Ilvesheim SPIN:I0426494 33/3020-543210 - Printed on acid -free paper To Joseph Weizenbaum Foreword by Joseph Weizenbaum Since the dawn of the age of computers, people have cursed the difficulty of programming. Over and over again we encounter the suggestion that we should be able to communicate to a computer in natural language what we want it to do. Unfortunately, such advice rests upon a misconception of both the computer and its task. The computer might not be stupid, but it is stubborn. That is, the computer does what all the details of its pro­ gram command it to do, i.e., what the programmer "tells" it to do. And this can be quite different from what the programmer intended. The misun­ derstanding with respect to tasks posed to the computer arises from the failure to recognize that such tasks can scarcely be expressed in natural language, if indeed at all. For example, can we practice music, chemistry or mathematics without their respective special symbolic languages? Yet books about computers and programming languages can be written more or less reasonably, even if they are not quite poetic or lyrical. This book can serve as an example of this art and as a model for anyone at­ tempting to teach inherently difficult subject matters to others. Klagenfurt, April 1995 Preface Striving to make learning to program easier, this book addresses primarily students beginning a computer science major. For our program examples, we employ a new, elegant programming language, Modula-3. However, most of the concepts that we introduce apply and are relevant indepen­ dently of the specific programming language. This book can either accompany an introductory lecture on program­ ming or serve self-study purposes. Both cases absolutely demand hands-on programming practice in addition to reading the book. Perusing a book on programming in dry dock without ever navigating the challenging waters of programming would be like reading about how to playa violin without ever touching the instrument. Learning to program means mastering both theory and practice, preferably simultaneously. Newcomers to a computer science major bring with them a broad range of different backgrounds. Some have no computer literacy, while others can handle certain application programs such as word processors or spread­ sheets. Still others have programming experience, although the breadth and depth of their skills varies greatly. This book assumes no particular prerequisites. A reader armed with normal high school mathematics and rudimentary computer literacy should be able to understand this book. We begin with fundamental concepts and only stepwise introduce the more dif­ ficult, higher-level concepts that build on them. To avoid the risk of bore­ dom, students with a higher level of programming experience should feel free to skim over exhaustive explanations that are already clear to them. Organization of the Book The book consists offive parts: 1. Introduction In the first chapter we cast light on the term programming from var­ ious perspectives and show their relative importance in the field of computer science. The second chapter introduces a formal notation for the precise specification of the syntax of programming languages. x 2. Introduction to Programming Chapters 3 to 10 introduce the classical programming concepts. Be­ ginning with a sequence of statements and many simple and user­ defined static types, these chapters move on to arm the reader with procedures, functions and modules to be able to correctly structure even complex problems. On completion of Chapter 10, the reader should be able to write many challenging programs. 3. Advanced Programming Here we introduce a number of concepts that particularly support the development of program systems that need to react to ever changing sets of data. We present dynamic data structures as well as recur­ sion at the algorithmic and data-structure level. The reader also be­ comes familiar with persistent data and exception handling. Chapter 13 treats object-oriented programming, which has conquered an ever growing share of the field of software system development. Another steadily rising field, parallel programming, highlights Chapter 16. 4. Appendices Through the appendices we have striven to ease the task of Modula-3 programming. Appendix A describes a complete non-trivial program to manage music CD's. Appendix B, intended as a reference for the pros, offers a complete but very compact description of the semantics of Modula-3. It is a reprint of the original Modula-3 language defini­ tion [CDG+S9]. Further appendices describe the most important in­ terfaces to the Modula-3 development environment and provide con­ cise descriptions of various such environments. The appendices also include detailed instructions on installing and configuring a Modula-3 development environment and the software included with this book. 5. Included Software All examples in the book have been tested. They are either executable themselves or parts of executable programs. We provide these to the reader at no charge. All Modula-3 programs (including the Modula-3 compiler) can be started from an integrated, interactive, user-friendly environment. Acknowledgments Our foremost gratitude goes to Roland Mittermeir, who profoundly con­ tributed to the production of this book. Significant texts and examples in Chapters 10 to 12 come from him. He is actually a co-author of this book. We also owe special thanks to Hans-Peter Mossenbock, Peter Rechen­ berg, Johann Eder and Karl-Heinz Eder; they assumed the enormously Xl work-intensive and thankless task of thoroughly proofreading the origi­ nal German manuscript. We likewise wish to express our gratitude to Michael Dobrovnik for his comments on our example program in the ap­ pendix. Their criticisms and comments taught us a great deal, and without their contributions it would have been impossible to complete this book. Naturally the authors retain full and sole accountability for any errors. Our gratitude also goes to the researchers at Digital Systems Research Center, Palo Alto, who developed Modula-3 and made it available. We es­ pecially thank Marc Najork, for his support. We are also grateful to Greg Nelson and Bill Kalsow. We also extend our appreciation to Springer-Verlag, Digital Equipment Corporation, the University of Klagenfurt and the Raiffeisen Bank of Ca­ rinthia for their generous support of the development of our user-friendly Modula-3 environment and to Miklos Szabo for his development work. We also offer our sincere thanks to Silvia Nedizavec for her meticulous preparation of the figures in this book and to Michael Vrbicky for his help in formatting the English edition. Last but not least, we thank our patient families, who spent many evenings and weekends without us during the two years in which we wrote this book. We offer the reader this book as the fruits of our labors in the hope that it proves to be a useful learning instrument and that it provides some fun and pleasure along the way. Contents 1 What is programming? 1 1.1 An informal introduction. 1 1.1.1 Algorithms ..... 2 1.1.2 Switches and symbols 4 1.1.3 Turing machine ... 6 1.1.4 Computability .... 7 1.2 The von Neumann computer. 9 1.3 Rigid thought structures ... 11 1.4 Programming in the small . 14 1.4.1 Software production methods 14 1.4.2 Writing simple programs ... 17 1. 5 Levels of programming . 18 1.5.1 Formal and human languages. 18 1.5.2 Assembler ........... 20 1.5.3 High-level programming languages. 21 1.6 Programming and computer science .... 24 1.6.1 The responsibility of computer scientists 25 2 Metalanguages 27 2.1 Definition of formal languages . 27 2.2 Digits and numbers . 29 2.3 Names ............
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages19 Page
-
File Size-