JAMES A. BROWN
SANDRA PAKIN
RAYMOND P. POLIVKA
This book introduces the programming language APL2. APL2 is an extension to and generalization of the programming language APL.
APL2 is an ideal language for solving business, engineering, and scientific problems in an interactive computer environment. With this book you learn APL2 by concentrating on the data structures and programming techniques needed to solve these problems. Youll see how to use APL2 to manage data, to model environments, and to state complex relationships and solve equations.
APL2 at a Glance presents APL2 and demonstrates its distinguishing features (particularly its use of arrays of arrays and user-defined operators). It is divided into eight chapters, each of which includes numerous examples to demonstrate the ideas presented. Each chapter also includes exercises to provide practice in applying the information covered.
Whether youre a novice or a seasoned programmer, youll appreciate the emphasis here on the language and its applications. This book gives you a solid basis for good APL2 programming practices and style.
Also from Polivka and Pakin
APL: The Language and Its Usage
A complete and comprehensive presentation of the language intended for the problem solver. This book is organized to enable users to solve real and significant problems as they are introduced to APL functions and concepts.
PRENTICE HALL, Englewood Cliffs, N.J. 07632
ISBN 0-13-038670-7
Contents
Preface
Why learn APL2 ?
Computers do precisely what people program them to do. If you want to be in control, you need a way to tell the computer what you want it to do. Just as people invented languages so they could communicate with each other, people invented programming languages so they could communicate with computers and tell them what to do.
APL2 (A Programming Language-2) is a language designed to facilitate both kinds of communication. It is a precise and concise notation for the recording of ideas. It is perfectly suited for such diverse applications as commercial data processing, system design, mathematical and scientific computation, data base applications, Artificial Intelligence, and teaching. It does not suffer from the inaccuracies and vagueness of natural languages (like English). You can use it as a tool for working out the solution to a problem and then, unlike mathematics or other tools, you can use the computer directly to calculate the solution.
Of the many programming languages available, APL2 has these distinguishing features:
Few rules. You will know most of the everyday rules for writing APL2 after you read . APL2 s rules are simple, and you can learn to write correct expressions immediately.
Arrays. APL2 deals with whole collections of data all at once. APL2 has arrays as the fundamental unit of computation.
Rich set of functions. The APL2 language includes a wide variety of functions. These functions apply to whole arrays at one time.
Operations on functions. APL2 has operators that modify functions, creating whole families of related functions in a uniform manner. You can pass functions as parameters to programs.
User operations. When you write programs in APL2 , you create your own functions and operators, which behave like the functions and operators defined as part of the language.
APL2 at a Glance introduces APL2 and demonstrates these distinguishing features. No prior APL experience is assumed; however, even a seasoned APL programmer will find the book valuable because of its emphasis on the APL2 data structures and the style of programming brought about by its new functions and operators.
Designed for private study or use in a classroom, APL2 at a Glance contains eight chapters that present the basic features of APL2 :
introduces APL2 and shows how APL2 handles data and performs operations. It defines important APL2 terms and explains how to respond to error messages.
explains the fundamental array structure of APL2 and describes several operations that manipulate vectors.
describes the ways in which you can expand upon the set of operations APL2 provides. It discusses the use of operators and introduces APL2 programming.
presents system commands for saving, loading, copying, and listing variables and programs.
to all arrays and provides operations for measuring, structuring, and manipulating arrays.
introduces operations for comparing, calculating, selecting, searching, and sorting of data.
describes branching, program debugging, prompting for input, controlling output, iteration, and recursion.
demonstrates the development of APL2 applications by showing three applications: recordkeeping for a magazine collection, simulation of a vector computer, and Artificial Intelligence for solving puzzles.
Each chapter includes copious examples to demonstrate the ideas presented and exercises to give you practice in applying the information presented in the chapter.
If possible, you should try out examples on a computer as you read. To do this, you need to determine how to access APL2 on your system, how to use the terminal or keyboard to enter and display the APL2 character set, and how to use other features that may vary from one APL2 implementation to another.
Besides trying the examples, you can improve your understanding of APL2 by working the exercises. The exercises are of two types: practice in evaluating APL2 expressions and problems involving creation of APL2 expressions and programs. The answer key at the end of the book provides solutions to even-numbered problems.
APL2 at a Glance covers the basic APL2 features. The final section, summarizes other APL2 features and capabilities.
The book concludes with several appendices, a glossary, bibliography, and an index.
Acknowledgments
Without the encouragement, thoughtful reviews, and critical comments of colleagues, family, and friends, APL2 at a Glance would have been a lesser book. We acknowledge with appreciation and respect the efforts of so many: Doug Aiton, Ev Allen, Luanne H. Amos, Anne Baldwin, Yonathan Bard, Phil Benkard, Norman Brenner, Karen Brown, Gary Burkland, Bill Buscher, Thomas W. Conrad, Dick Dunbar, Ed Eusebi, Sylvia Eusebi, Kenneth Fordyce, Bill Frank, Erik S. Friis, John Gerth, Julie Gerth, Jon Goodblatt, Sandra K. Gomez, Alan Graham, Brent Hawks, Bjorn Helgason, Bill Hillman, Evan Jennings, Howard Kier, M. J. Kingston, Joseph W. Lacenere, Jr., Stephen M. Mansour, Claudio Marescotti, Theodoro Marinucci, Blair R. Martin, Jonathan McCathy, Tom McCleskey, Jon McGrew, Yutaka Morita, Dan H. Norton, Jr., Richard Oates, Scott Pakin, William C. Rodgers, James P. Russell, Bob Sayles, David Selby, Cory Skutt, Darryl O. Smith, Richard C. Stitt, Norman Thomson, Beth Rush Tibbitts, Jean-Luc Verspieren, Russ Washburne, Nancy Wheeler, Ron Wilks, Sheryl Winton, Karen Youmans, and Marty Ziskind. Nevertheless, any errors or omissions in the text are our responsibility and not those of the people listed here.
We also thank International Business Machines Corporation ( IBM ) and Sandra Pakin & Associates, Inc. ( SP&A ) for their support and cooperation. Special thanks and much appreciation go to Jon McGrew for producing The APL Gazette and for his extraordinary help in the production of this book.