← An Introduction to Programming Using Macintosh Pascal

An Introduction to Programming Using Macintosh Pascal

From the originals

12 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

Image 1

An Introduction to Programming using Macintosh Pascal Paul Pritchard Macintosh Plus Macintosh SE

A dark book cover with white and icon-decorated title lettering above a photo of three Macintosh computers on a desk, with the author name in blue at the bottom.

Reading notes: Small screen text on the computer displays is too blurred to transcribe and was not included. Small text on the Macintosh SE and Macintosh Plus labels is legible but the trademark symbol after Macintosh in the title is rendered as TM in a circle and was omitted from the transcript.

Printed product names
Macintosh Plus · Macintosh SE · Macintosh Pascal
Languages
English
PDF page 1

AN INTRODUCTION TO PROGRAMMING USING MACINTOSH™ PASCAL Paul Pritchard Macintosh Plus Macintosh SE

A dark book cover with colorful Macintosh-style interface icons framing the title above a photo of three beige Apple computers on a desk, with the author's name in light text at the bottom.

Reading notes: Small on-screen text in the monitor displays (menu bars and diagram labels such as 'CROSS SECTION OF ENGINE ASSEMBLY' and 'FIGURE 7-75') is too small or blurred to transcribe reliably and was omitted. Title is set in stylized letters interspersed with icons; spacing around icons is approximate, so the headline is given with standard word spacing.

Printed product names
Macintosh · Macintosh Plus · Macintosh SE · Pascal
Languages
English
PDF page 2 · PDF page 5

A completely blank white page with no visible artwork, layout elements, or text.

Reading notes: The image appears entirely blank; no visible text was found, so all printed fields are empty.

PDF page 3

AN INTRODUCTION TO PROGRAMMING USING MACINTOSH™ PASCAL

AN INTRODUCTION TO PROGRAMMING USING MACINTOSH™ PASCAL PAUL PRITCHARD UNIVERSITY OF QUEENSLAND ADDISON-WESLEY PUBLISHING COMPANY Sydney • Wokingham, England • Reading, Massachusetts Menlo Park, California • New York • Don Mills, Ontario Amsterdam • Bonn • Singapore Tokyo • Madrid • San Juan

Languages
English
PDF page 4

An introduction to programming using Macintosh Pascal

© 1988 Addison-Wesley Publishers Limited © 1988 Addison-Wesley Publishing Company All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the publisher. The programs presented in this book have been included for their instructional value. They have been written and tested with care but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs. Cover design by 20/20 Graphics, Iver, Bucks. Text design by Roger Walker/Linde Hardaker. Typeset by Morton Computer Services Ltd, Scarborough. Printed in Singapore First printed in 1988. Reprinted with corrections in 1988. Third printing, 1989. British Library Cataloguing in Publication Data Pritchard, Paul An introduction to programming using Macintosh Pascal. 1. Macintosh (Computer) - Programming 2. PASCAL (Computer program language) I. Title 005.2'65 QA76.8.M3 ISBN 0-201-17539-8 Library of Congress Cataloguing in Publication Data Pritchard, Paul, 1951- An introduction to programming using Macintosh Pascal I Paul · Pritchard p. cm. On t.p. the registered trademark symbol "TM" is superscript following "Macintosh" in the title. Includes index. ISBN 0-201-17539-8: 1. Macintosh (Computer) - Programming. 2. Pascal (Computer program language). I. Title. QA76.8.M3P75 1988 87.3186D 005.'265-dc 19

Reading notes: Superscript trademark symbol after 'Macintosh' in title is noted but its exact rendering is uncertain. Some words in the source show spacing irregularities that may reflect OCR artifacts.

Printed product names
Macintosh Pascal
Printed dates
1988 · 1989 · 1951
Languages
English
PDF page 6

PREFACE This book is aimed primarily at students taking an introductory course in computer programming, where the programming language is Pascal, and practical work is done using either Macintosh Pascal or Lightspeed Pascal. t It is intended to be suitable for both one-semester (half-year) and two-semester (full-year) university-level courses. It contains: • A modem and thorough introduction to solving programming problems in a procedural language; • A self-contained guide to the use of the Macintosh and the Macintosh Pascal programming environment; • A complete description of ANSI Standard Pascal; • A complete description of Macintosh Pascal's extensions to and deviations from Standard Pascal; and • A thorough introduction to the use of Macintosh Pascal's librar- ies for graphics and numeric programming. The reader is not assumed to have had any previous exposure to computers or programming, or any mathematical background beyond the level of simple high-school algebra. Nevertheless, the book should prove useful to those with prior programming experience. The sections that follow elaborate on the book's objectives. It is left to the reader to judge how appropriate these are and how success- fully they have been met. The proof is in the pudding, not in the pre- face. Philosophy The emphasis is fairly and squarely on problem-solving in the domain of programming. Every opportunity is taken to expose the reader to new problems, and to increase the reader's problem-solving ability t'Macintosh Pascal' will refer to both Macintosh Pascal and Lightspeed Pascal, unless other- wise indicated. PREFACE vii

Reading notes: Stray character 't' before 'It is intended' may be an OCR artifact Page marker 'PREFACE vii' and footnote text appear mid-passage, so reading order may be uncertain

Printed product names
Macintosh Pascal · Lightspeed Pascal
Languages
English
PDF page 7

gradually. Particular emphasis is placed on stepwise refinement and program schemas. Each program is developed from its specifications, not presented as a fait accompli. Invariants are presented as of practical rather than theoretical interest. They are implicitly used from the start, and are explicitly identified first in Chapter 11, on one-dimensional arrays, in the guise of general pictures. Learning a programming language is of secondary importance. Nevertheless, the student is entitled to a careful and complete descrip- tion of the language he or she is using, and will find it in this book. Because programming to a recognized standard is important, Standard Pascal is defined as well as Macintosh Pascal, and the differences are described. And whenever one of Macintosh Pascal's predefined sub- programs is introduced, it is properly specified. Case-studies Few would dispute that it is very desirable for the beginner to be exposed to a variety of exemplary programs, but programming is the thought process that culminates in a program, not the finished product. Accordingly, a dozen case-studies are tackled and each results in a sub- stantial, meticulously written program that illustrates the use of a particular feature of Pascal. All but one of these programs is (not was) developed from its specifications using stepwise refinement. Care has been taken to explain every significant design decision. Most of the case-studies are much larger programming problems than are typically found in introductory texts, and lead to correspond- ingly larger programs. It is essential for students to be exposed to such problems as early as possible, lest they develop problem-solving habits that do not scale up. Although stepwise refinement reduces large problems to many small ones, it is the programmer who formulates these problems, using skills quite different from those used in solving small, given programming problems (exercises). The student is not asked to solve these large problems, only to follow the processes of their solutions. Programming style This book treats the matter of programming style seriously. All pro- grams and program fragments are written in a consistent and dis- ciplined style, the main features of which are: • Documentation of the process of stepwise refinement by means of comments representing high-level actions; viii PREF ACE

Reading notes: Source is a book preface excerpt with no visible advertised products or prices; headline not identifiable Text begins mid-sentence and ends mid-list, indicating a partial page

Printed product names
Macintosh Pascal · Standard Pascal
Languages
English
PDF page 8

• Documentation of the meaning of each variable (unless it is clear from its name or obvious from the context of its use); • Specification of all (sub)programs; and • Eschewing global variables. Every program or fragment of a program is written in accordance with these principles. Style of presentation The philosophy is to expose the student early to a significant sub- language (the required simple types, basic control structures, textual input and output), and then to start solving problems. Further language constructs are introduced as needed, always in a problem- solving context. Repetition accordingly precedes procedures and functions - no significant problem-solving can be done without it, and to do otherwise is to emphasize language issues when they are not important and cannot be appreciated. Subprograms are the next cab off the rank though, since they are needed as soon as programs get sufficiently complex. Problems are chosen carefully to require only the language features at hand - problems that have significantly superior alterna- tives using unfamiliar features are avoided. In any case, the reader is informed whenever new features or concepts can be used to improve a solution, and the improvement appears either in the text or as an exercise. Syntax is presented formally, in a highly simplified adaptation of Extended Backus Naur Formalism (EBNF), that uses typographic devices and familiar conventions in preference to special grammatical symbols, thereby achieving a written form that is as close as possible to that used in the display of Macintosh Pascal programs. Section A.3 of the Appendix presents the complete syntax of ANSI Standard Pascal in syntax diagrams, and Section A.4 gives a brief explanation of EBNF notation. Exercises There are a great many exercises. Most have solutions at the end of the book. They are arranged to follow the order of material within each chapter, so that it is not necessary to complete a chapter before embarking on the early exercises. No indication of the difficulty of PREFACE ix

Reading notes: Source text is a book preface fragment, not an advertisement; no headline or product or price information is present. Opening bullet list is truncated at the start of the supplied excerpt.

Languages
English
PDF page 9

:1:iY 0.0 exercises is given. This is a deliberate policy - the difficulty of a programming problem depends on the programmer as much as the problem, and programmers are not normally given difficulty-ratings for their programming tasks. None of the exercises is meant to be beyond the ability of a beginner of average talent. Exploiting the Macintosh This text was conceived to exploit the rich, predefined libraries of Macintosh Pascal to give more realistic and interesting examples than are possible in a generic Pascal text. A thorough, self-contained introduction to the Macintosh, and to Macintosh Pascal as a programming environment, is given in Chapters 1, 2, and 4. The Macintosh's graphics capabilities are exploited in many case-studies, with an emphasis on getting meaningful and attractive results from a small body of graphics knowledge. Gimmicky programs that produce gee-whiz effects are conspicuously absent - programs are always written to specifications, not to see what interest- ing displays they might produce. Macintosh Pascal's extensions for string-processing, which are very attractively done in the main, are exploited in Chapter 14. Chapter 15, on records, indicates how to implement Macintosh Pascal's string-types in Standard Pascal as an abstract data type. Macintosh Pascal's facility to open random-access files permit- ting mixed reading and writing is explained in Chapter 16. Situations in which Lightspeed Pascal differs from Macintosh Pascal are indicated by numbered icons in the margin. These refer the reader to Section A.5 in the Appendix. Although these icons officially represent bug spray cans, for our purposes they are better regarded as sources of light; candles are the obvious choice. About the chapters • Chapters 1 and 2 introduce the Macintosh and Macintosh Pascal's editor. Their exercise sections lead the reader at a Macintosh systematically through all the important aspects. • Chapter 3 previews Pascal, following the 'Reading Before Wri- ting' school of language learning. It introduces the 'Macaveats' sections that inform the reader of the differences between Macintosh Pascal and ANSI Standard Pascal. Several have been discovered that are not documented by Apple. x PREFACE

Reading notes: Leading fragment ':1:iY 0.0' at start of source is unclear and may be OCR noise. Text appears to be a book preface with no primary heading, so headline is null. Reading order of marginal icon reference and 'About the chapters' section may not be exact.

Languages
English
PDF page 10

• Chapter 4 documents the sophisticated execution features of Macintosh Pascal, and illustrates them using the programs pre- sented in Chapter 3. • Chapter 5 introduces our method of syntax definition, and pre- sents a sublanguage that will enable the reader to embark on significant problem-solving. • It is with Chapter 6 that problem-solving starts in earnest. It in- troduces stepwise refinement and program schemas, and exemplifies thoroughly the use of both in its two case-studies. • Chapters 7 and 8 introduce functions and procedures, respect- ively. They are akin in style to Chapter 5, concentrating on explaining these new language features. The examples use sub- programs to give improved solutions to previous problems. • Chapter 9 presents two case-studies that exploit subprograms to solve new problems. It also introduces the fundamentals of Macintosh graphics that are heavily used thereafter. • Chapter 10 gives the whole story on ordinal types and their associated control structures, in preparation for the following chapter on arrays. Nevertheless, it contains a substantial case- study that thoroughly exploits user-defined types, and provides notes for a further case-study involving graphics in its exercise section. • Chapter 11, on one-dimensional arrays, is the most important chapter for an introductory course. Many interesting problems can be tackled and the opportunity arises to present invariants in a very natural way (through general pictures). Its case-study demonstrates the wisdom of writing general procedures - the graphics for n -processor scheduling use exactly the same procedures as for two-processor scheduling. • Chapter 12 rounds out a most thorough introduction to pro- gramming with a discussion and illustration of two important aspects of programming methodology, namely, correctness and efficiency. Ideally, a one-semester course would cover these first twelve chapters. The remaining chapters do not so much follow on from the ones men- tioned as cover special topics. Instructors who, for example, like to in- troduce sets, records, recursion or string-processing in a first course, should have minimal difficulty selecting the chapters or sections of interest. These chapters contain exercises that do not rely on all the special topics covered previously. There are some dependencies in these chapters: PREFACE xi

Reading notes: Possible hyphenation or line-break artifacts in 'n -processor' and 'one-dimensional' spans; reading order follows source text as supplied.

Languages
English
PDF page 11

• Chapter 16 (on files) should be read after Chapter 15 (on re- cords) as is natural; • Case-study 11 in Chapter 18 makes use of sets (treated in Chapter 17) and Macintosh Pascal strings (treated in Chapter 14); and • Chapter 20 (on dynamic data structures) assumes knowledge of the material in Chapter 15 (on records) as is inevitable. Software supplement The dozen case-studies are substantial programs. Some of the exercises invite the reader to trace their execution, or to make certain modifica- tions. A software supplement, available from the author, includes all the case-studies and complete subprograms in the book (together with test-drivers when necessary). Any of these programs may be copied freely for non-commercial purposes, provided that they are copied in full (with the source and copyright information retained). For ordering information, write to ·'Dr Paul Pritchard, Depart- ment of Computer Science, University of Queensland, St Lucia, Australia 4067'. Alternatively, e-mail may be sent to the author at one of the following addresses: ACSnet: pap@uqcspe.oz ARPA: pap%uqcspe.oz@uunet.uu.net CSNET: pap@uqcspe.oz UUCP: ... !uunet!munnari!uqcspe.oz!pap JANET: uqcspe.oz!pap@ukc Suggestions for improvements to the book are also most welcome, as are unsolicited testimonials. xii PREFACE Paul Pritchard St Lucia, September 1987

Reading notes: Possible OCR spacing artifacts in hyphenated words such as 're-cords' and 'pro-gram'; the heading 'PREFACE' appears only as a running page marker, so no primary headline is assigned. Quoted address line 'Dr Paul Pritchard' uses unusual quotation marks that may be damaged characters.

Printed dates
September 1987
Languages
English
PDF page 12

ACKNOWLEDGMENTS The material in this book is based on courses given by the author in the Department of Computer Science at Cornell University, and later at the University of Queensland, Australia. Some of it has evolved from the rich store of material accumulated over the years by the professors who taught CSIOO at Cornell: to my former colleagues Tim Teitelbaum (especially), Ken Birman, Alan Demers, John Gilbert, Dale 'Downhill' Skeen, and Kay Wagner, my thanks. John Gilbert kindly permitted me to adapt his notes on floating-point arithmetic. The neat sequence of three case-studies on job scheduling was suggested by Nava Aizikowitz. My antipodean colleague, Gordon Rose, generously allowed me to adapt his program for Case-study 12; Mike Henning did likewise for his notes on the Macintosh and Macintosh Pascal. And back in the USA, Chanderjit Bajaj graciously performed important cultural re- search on my behalf. I am indebted to David Gries for giving me my chance in the Big Time, for serving as Master to my Apprentice in the art of pro- gramming and for his generosity in agreeing to review the manuscript. Andrew Lister gave me the flexitime needed to write the book, and together with other members of the Department of Computer Science at the University of Queensland, helped provide an environment con- ducive to writing and typesetting. Jim Welsh and John Elder produced syntax diagrams worth emulating. Niklaus Wirth, the Macintosh development team, and the Macintosh Pascal and Lightspeed Pascal development teams, respectively, created a language, a computer, and two programming environments worth writing about. Thanks to all of the above, to C.A.R. Hoare for his encouraging assessment of the book's quality, to Stephen Troth of Addison-Wesley for his support and professionalism, to the reviewers for their constructive suggestions, and to Cheryl Pritchard for proof-reading. Finally, my thanks go to Errol Martin and bzalp Babaoglu for their friendship and encourage- ment, and with most gratitude, to Cheryl and Roxanne for their love and forbearance. The author and publishers also wish to thank the following for permis- sion to reproduce figures and quotations: ACKNOWLEDGMENTS xiii

Reading notes: OCR-like spacing and character errors such as 'CSIOO', 'bzalp Babaoglu', and 'Chanderjit Bajaj' may be misread Page-number line 'xiii' at end is separated from its heading context

Languages
English