← The First Book of Macintosh Pascal

The First Book of Macintosh Pascal

From the originals

13 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

Osborne McGraw-Hill THE FIRST BOOK OF Macintosh™ Pascal PAUL A. SAND

A gray book cover with a red band at top holding the Osborne McGraw-Hill logo, bold white title type with a red dot over the i in Macintosh, and a scatter of overlapping colored rings with radial lines in red, yellow, green, lavender and dark purple in the lower right.

Reading notes: The trademark symbol after Macintosh is small and may be read as ™ rather than a separate mark; the logo text is set in a stylized wordmark where 'Graw-Hill' is rendered in a heavy face. Author name is printed in the lower left and is the only attribution visible.

Languages
English
PDF page 1

Osborne McGraw-Hill THE FIRST BOOK OF Macintosh™ Pascal PAUL A. SAND

A gray book cover with a red band at the top bearing the Osborne McGraw-Hill logo, large white bold title text on the left, and a scatter of overlapping colored rings with line hands in yellow, green, red, purple, and dark purple on the right and lower portion, with author name in the bottom left.

Reading notes: The 'Macintosh' trademark symbol ™ is printed as a small superscript to the right of the word, transcribed here as ™. Faint wear marks and spots on the cover are not transcribed as text.

Languages
English
PDF page 2

The image is a entirely blank white page with no visible artwork, layout elements, or text.

Reading notes: No visible text found in the image; transcript and printed fields left empty.

PDF page 3

The image is a entirely blank white page with no visible artwork, layout elements, or text.

Reading notes: No visible text found; the page appears blank white.

PDF page 4

THE FIRST BOOK OF MACINTOSH™ PASCAL

Published by Osborne McGraw-Hill 2600 Tenth Street Berkeley, California 94710 U.S.A. For information on translations and book distributors outside of the U.S.A., please write to Osborne McGraw-Hill at the above address. Copy II Mac is a trademark of Central Point Software, Inc. Macintosh is a trademark of Apple Computer, Inc. THE FIRST BOOK OF MACINTOSH™ PASCAL Copyright © 1985 by McGraw-Hill, Inc. All rights reserved. Printed in the United States of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a data base or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication. 234567890 DODO 898765 ISBN 0-07-881165-1 Cindy Hudson, Acquisitions Editor Paul Hoffman, Technical Editor Catherine Pearsall, Copy Editor Cheryl Creager, Composition Yashi Okita, Cover Design

Reading notes: Publisher address and distributor line are partially ambiguous in reading order.

Printed product names
Copy II Mac · Macintosh
Printed dates
1985 · 1976
Languages
English
PDF page 5

CONTENTS Introduction vii Chapter 1 Getting Started With Macintosh Pascal 1 Chapter 2 Variables and Loops 29 Chapter 3 Macintosh Pascal: Editing and Disk Use 83 Chapter 4 Decision Making 101 Chapter 5 Macintosh Pascal Debugging Aids 131 Chapter 6 More Data Types 151 Chapter 7 Introduction to Library Functions 175 Chapter 8 Introduction to Library Procedures 213 Chapter 9 Your Own Procedures and Functions 257 Chapter 10 Your Own Data Types 289 Chapter 11 Structured Data Types: Arrays, Records, and Sets 303 Chapter 12 Macintosh Pascal Structured Types 349 Index 403

Reading notes: Headline inferred from the table of contents label; no separate primary heading is printed. Some chapter titles are split across lines, so reading order of wrapped entries may be ambiguous.

Languages
English
PDF page 6

INTRODUCTION This book is an introduction to the Pascal programming lan- guage and to the version of that language on the Apple Macintosh computer. You can use this book regardless of your level of expertise in computer programming. If you are an absolute beginner, don't worry; it is our assumption that you know nothing about either programming in general or Pascal in particular. We will explain everything you need to know in order to write, enter, and run programs in Pascal on the Macintosh. Even if you already have some familiarity with the Pascal programming language, you will find this book useful. Macintosh Pascal is like no other version of Pascal you have ever used-just as the Macintosh itself is like no other com- puter you have used. We will attempt to explain and demon- strate many of the major features of Macintosh Pascal, espe- cially thos·e that aren't found in "Standard" Pascal. Book Philosophy Computer programming is a skill that is learned by doing. No book yet written can take the place of the actual experience you will gain in designing and writing your own programs. Realizing this, we will not. promise that simply reading this book will make you a seasoned expert in Macintosh Pascal; our goals are more modest. This book will • Provide you with a description of Macintosh Pascal's fea- tures and how these features are used in programs. vii

Reading notes: Hyphenated line breaks and a stray 'thos·e' spelling in the source copy Line-broken word 'lan-guage' and 'de-monstrate' spacing may affect reading

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

• Give you the rules of the language: what is legal, what isn't legal. • Show you many examples of Macintosh Pascal pro- grams that demonstrate how the language can be used to access many of the hardware and software features of the Macintosh itself. • Provide you with some suggestions for changing the programs presented here as well as ideas for your own programs. Ideally, this should get you started in learn- ing how to program on your own. In general, the emphasis in this book will be on the final two points: to show you how Macintosh Pascal works and to spark your own curiosity enough to discover more on your own. We will lean heavily on example programs throughout the text to accomplish this. Somewhat less emphasis will be placed on the more "for- mal" aspects of Pascal: the precise rules that make one Pas- cal statement legal and another one unacceptable. Many of the formal rules of Pascal are designed to make sense of very unusual program constructions, ones unlikely to occur in everyday programming. We will forego explaining such rules in all their mind-numbing detail. Instead, we will concentrate on developing your intuitive sense for what's right and what's wrong in Pascal. As a user of Macintosh Pascal, you own or have access to the documentation provided with the Macintosh Pascal soft- ware. You should look upon this book as a supplement to the Macintosh Pascal documentation, not as a replacement. The Macintosh Pascal reference manuals are complete, concise, and rigorous. This approach has the advantage that you may look there for the exact rules on what you may or may not do in your Pascal programs. The disadvantage is that it is diffi- cult for programming novices and other programmers not familiar with Macintosh Pascal to sort through the descrip- tions of every last nit-picking rule and restriction to extract the truly useful information present in the reference manuals: the knowledge you will need every time you write a Pascal program. In this text, we provide a more leisurely and less formal introduction to Macintosh Pascal. We concentrate on the "good parts" of Macintosh Pascal: those that can be used eas- ily by both programmers unfamiliar with either Pascal and viii The First Book of Macintosh Pascal

Reading notes: Reading order may be affected by two-column layout and a bullet list at the start of the excerpt.

Printed product names
Macintosh Pascal
Languages
English
PDF page 8

programmers who know Pascal but may not be acquainted with the Macintosh's version of the language. Why Learn to Program? As you probably know, everything the Macintosh (or any other computer) does is controlled by its software: programs that tell the computer what to do in various situations and how to accomplish useful tasks. Learning to program is, simply stated, discovering how to tell the computer to "do things." For many people, computer use is restricted to using pro- grams someone else has written. Given the increasing sophis- tication and usefulness of commercially available computer software, this is a perfectly workable strategy for many, if not most, computer users. You have an inalienable right not to learn to program your computer, if you so choose. Having said that, however, here are some reasons why you might, after all, want to undertake the task of writing your own programs: • Learning to program will give you a better idea of how the computer works and what it can and cannot do. • Programming is, like mathematics, an intellectual dis- cipline that is inherently worth knowing. • Knowing how to program can stand you in good stead when a computer problem arises at work or at home for which no available prewritten software applies. Depend- ing on your expertise, you may be able to write a pro- gram to solve the problem, often with less time and expense than if you had sought commercially available software for the same purpose. • Programming can be profitable. People who don't know how (or don't have time) to program will pay you money to make their computer jump through designated hoops. • Last, but not least, programming is fun-a truly end- less source of amusement. If you enjoy intellectual chal- lenge, thinking a problem through to its solution, and the sense of accomplishment that occurs when some- thing works as it should, you will find programming to be immensely enjoyable. In a sense, programming is the ultimate computer game. Introduction ix

Printed product names
Macintosh · Pascal
Languages
English
PDF page 9

Why Learn Pascal?

Why Learn Pascal? If you decide to learn to program, you need to learn at least one programming language. In this book, obviously, we are suggesting you learn the programming language called Pas- cal. Pascal was developed in the late 1960s by Niklaus Wirth. His aims were to produce a language suitable for teaching programming concepts clearly and systematically and to make the language usable on a large number of computers. His success is obvious: Pascal's popularity has increased rapidly since its introduction, and versions of the language are available on many computers, ranging from small, inex- pensive personal computers to large mainframe systems. Why is Pascal so popular? The primary reason is that Pas- cal makes the job of writing, reading, and modifying comput- er programs easier than do many other programming languages. Here are some ways in which Pascal is a convenient lan- guage for programmers. (You need not worry if you don't understand all or any items on this list, by the way. We'll be seeing how all these things work later.) • Pascal has "structured" control statements (while, repeat, for, case, and if-then-else) that allow the pro- grammer to write clear and concise code with the flow of control proceeding from top to bottom. The control flow in programs written in languages lacking these structured control statements often contains complex webs of if tests and goto statements. Such programs are often called "spaghetti code" because they are so diffi- cult for even experienced programmers to untangle. • Pascal permits the programmer to break up a large program into smaller, relatively independent procedures and functions, each one of which performs a single, eas- ily understood task. Each procedure or function can have its own set of "private" variables that are only used when that procedure or function is executed. Each procedure or function has well-defined input and output parameters used for communicating with its calling routine. This decomposition of a large program into modules greatly aids the programmer in both the initial design of the program and also in any subsequent modi- fications to the program; the modules can also be reused x The First Book of Macintosh Pascal

Reading notes: Running page header 'The First Book of Macintosh Pascal' and page number 'x' are at the end of the copy; reading order is otherwise continuous.

Printed product names
Pascal · Macintosh Pascal
Printed dates
1960s
Languages
English
PDF page 10

in subsequent programs, decreasing the overall pro- gramming effort. • Pascal allows programmers to define their own data types and data structures in addition to those already built into the language. Judicious use of this feature can make a program more compact and easy to understand. • Pascal allows the use of long identifiers for variables, procedures, and functions. This allows the programmer to use names with mnemonic significance, another aid in understanding a program. Although Pascal is a good computer language, it is not a perfect one. And it isn't suitable for all applications. Rather than go into Pascal's deficiencies here, however, we'll merely note that a good deal of serious software development is car- ried out in Pascal. And even if Pascal isn't your programming language of choice, you will find that learning Pascal will make learning and using other programming languages much easier. Why Learn Macintosh Pascal? As we will see in the first chapter, the "programming envi- ronment" provided by the Macintosh Pascal software is extra- ordinarily easy to use. In order to write Pascal programs on a typical computer system, you have to learn how to use a number of different programs, each with its own set of hard- to-remember commands and rules. This, fortunately, isn't the case with Macintosh Pascal: there are no complex command sequences to memorize, nor are there separate "editor," "compiler," or "debugger" programs to master. You need only learn to use the Macintosh Pascal software in order to be able to enter, run, and modify your own Pascal programs. Macintosh Pascal uses most of the conventional elements of the Macintosh user interface: pull-down menus, multiple overlapping windows on the screen, mouse selection, and so on. In fact, if you know how to use a word processing program like Mac Write or Microsoft Word, you already know nearly everything you need in order to enter your Pascal programs into the computer. Macintosh Pascal is therefore an excellent way to learn Introduction xi

Reading notes: Headline not clearly identifiable in supplied text

Printed product names
Macintosh Pascal · Mac Write · Microsoft Word
Languages
English
PDF page 11

the Pascal language. But that's not all: built into Macintosh Pascal is the capability for you to control nearly all aspects of your computer's operations. These capabilities include some not offered with languages costing many times more than Macintosh Pascal. (As before, you shouldn't worry if you don't understand everything-or anything-on this list as yet.) • Macintosh Pascal provides a variety of numeric data types that make it possible to write precise and reliable computational programs. • Macintosh Pascal supplies a number of extensions to the Standard Pascal language that make writing common application programs easier: there is a built-in string data type, an otherwise clause .on the case statement, sophisticated memory management, and direct-access file I/0 routines, to name a few. (These final two topics are relatively advanced, however, and won't be consid- ered in this text.) • Macintosh Pascal allows programs to access most of the capabilities of the Macintosh; for example, built-in rou- tines callable from Pascal programs allow your pro- grams to manipulate windows, use the mouse, the clock, and the sound generator. • Probably the most interesting feature is Macintosh Pas- cal's ability to call the QuickDraw routines and other software contained in the Macintosh's read-only memory. QuickDraw is an extensive "library" of routines that allows your programs to perform awesome feats of graphics magic. Macintosh Pascal, while an excellent learning environ- ment, is not suited to writing large application programs. In computer jargon, Macintosh Pascal is an interpreted lan- guage, rather than a compiled one. Compared to programs written in other languages, you may observe that your Macin- tosh Pascal programs are rather slow. (They may very well be fast enough for your purposes, however.) Also, your Pascal programs can't run "by themselves"; the Macintosh Pascal system must be present in the computer's memory at the same time. This imposes a relatively restrictive upper limit on the size of your Pascal programs. On balance, however, Macintosh Pascal is an excellent learning and programming tool for all but the most demand- ing applications. xii The First Book of Macintosh Pascal

Reading notes: Possible OCR artifact in 'I/0' (likely 'I/O') within the direct-access file I/O reference.

Printed product names
Macintosh Pascal · QuickDraw
Languages
English