Aldor User Guide
Total Page:16
File Type:pdf, Size:1020Kb
Aldor User Guide by Aldor.org Aldor User Guide c 2000 The Numerical Algorithms Group Limited. c 2002 Aldor.org. All rights reserved. No part of this Manual may be reproduced, transcribed, stored in a retrieval system, translated into any language or computer language or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright owner. The copyright owner gives no warranties and makes no representations about the con- tents of this Manual and specifically disclaims any implied warranties of merchantabil- ity or fitness for any purpose. The copyright owner reserves the right to revise this Manual and to make changes from time to time in its contents without notifying any person of such revisions or changes. Substantial portions of this manual have been published earlier in the vol- ume \Axiom Library Compiler User Guide," The Numerical Algorithms Group 1994, ISBN 1-85206-106-5. Aldor was originally developed, under the working name of A], by the Research Di- vision of International Business Machines Corporation, Yorktown Heights, New York, USA. Aldor, AXIOM and the AXIOM logo are trademarks of NAG. NAG is a registered trademark of the Numerical Algorithms Group Limited. All other trademarks are acknowledged. Acknowledgements Aldor was originally developed at IBM Yorktown Heights, in various versions from 1985 to 1994, as an extension language for the AXIOM computer algebra system. Aldor was further refined and extended at the Numerical Algorithms Group at Oxford, before the formation of Al- dor.org in 2002. The principal designer of the language was Stephen Watt, now Profes- sor of Computer Science at the University of Western Ontario. Many people have worked on the compiler, its documentation and the associ- ated libraries, including Gerald Baumgartner, Dave Bayer, Peter Broad- bery, Manuel Bronstein, Ronnie Brown, Florian Bundshuh, Bill Burge, Yannis Chicha, Robert Corless, George Corliss, Tim Daly, James Dav- enport, Mike Dewar, Samuel Dooley, Martin Dunstan, Robert Edwards, Marc Gaetano, Patrizia Gianni, Teresa Gomez-Diaz, Stephen Gortler, Johannes Grabmeier, Vilya Harvey, Ralf Hemmecke, Pietro Iglio, Tony Kennedy, Larry Lambe, Ian Meikle, Michael Monagan, Marc Moreno- Maza, Scott Morrison, Bill Naylor, Mike Richardson, Simon Robinson, Philip Santas, Jonathan Steinback, Robert Sutor, Themos Tsikas, Barry Trager, Mike West, and Knut Wolf. Thanks also to the management at IBM and NAG, in particular Brian Ford, Steve Hague, Shmuel Winorgrad, Bill Pulleyblank, Marshall Schor and Richard Jenks for their cooperation in bringing Aldor out of the laboratory and into the real world. i Preface Aldor is a programming language that attempts to achieve power through the uniform treatment of all values. Rather than build a language by adding features, we have tried instead to build a language by removing restrictions. While the design of Aldor emphasizes generality and com- posibility, it also emphasizes efficiency. Usually these objectives seem to pull in different directions. An achievement of Aldor's implementation is its ability to attain both simultaneously. Aldor is not at its foundation an object-oriented language. Instead, ob- ject semantics are reconstructed from the primitive treatment of func- tions and types as first-class values. Similarly, aspect-oriented program- ming arises as a natural use of general language primitives. While the ini- tial ro^le of Aldor was to replace the compiler component of the computer algebra system AXIOM, Aldor is not a reimplentation of the AXIOM programming language. Rather, Aldor reconstructs the essential aspects of the AXIOM programming language from more primitive notions. Aldor has been, over the period 1995-2001, available from the Numerical Algorithms Group (NAG) as part of the commercial AXIOM system. Over this period, Aldor's users began using it more and more outside of this original context, to the point where now most Aldor code is unrelated to AXIOM. It is now appropriate that Aldor have its own means of distribution for those who wish to use it in a general context, and Aldor.org has been formed for this purpose. The Numerical Algorithms Group has graciously consented to allow free distribution of Aldor this way. Bringing Aldor from a gleam in the mind's eye to a concrete compiler has been a substantial task. Considerable program analysis and optimiza- tion is required to reduce high-level source programs to efficient machine code. For the current release, the source of the compiler is approximately 135,000 lines of code, not including the run-time system, base library or iii other associated software. Here we have described Aldor 1.0, the first release of Aldor independent of AXIOM. Those who have used Aldor earlier will note that the present document has been adapted to refer to a new library, libaldor. This library has been used as there is now a considerable body of Aldor code based upon it. Manuel Bronstein and Marc Moreno Maza are to be thanked for having invested considerable efforts in its development. Marc Moreno Maza and Yannis Chicha have updated all the examples in this document to work with libaldor. Numerous individuals have contributed to Aldor over its development at IBM Research, the Numerical Algorithms Group, and elsewhere. These contributors should be listed in the acknowledgements section of this document. Particular thanks are due to Martin Dunstan who served as Aldor's steward at the Numerical Algorithms Group. It has been a true pleasure to work with such a collegial and insightful group of people. London, Ontario SMW January, 2002 iv Summary Contents I A brief overview of Aldor 1 1 Introduction .................................... 3 2 Some simple programs .............................. 9 II The Aldor programming language 19 3 Language orientation ............................... 21 4 Basic syntax .................................... 25 5 Expressions .................................... 37 6 Functions ..................................... 61 7 Types ....................................... 73 8 Name spaces .................................... 99 9 Generators ..................................... 113 10 Post facto extensions ............................... 119 11 Exceptions ..................................... 123 12 Generic tie-ins ................................... 129 13 Source macros ................................... 133 14 Language-defined types .............................. 137 15 Standard interfaces ................................ 151 v III The Aldor compiler 157 16 Understanding messages ............................. 159 17 Separate compilation ............................... 173 18 Using Aldor interactively ............................. 177 19 Using Aldor with C ................................ 191 20 Using Aldor with Fortran-77 ........................... 197 IV Sample Programs 205 21 Sample programs ................................. 207 V Reference 237 22 Formal syntax ................................... 239 23 Command line options .............................. 251 24 The unicl driver ................................. 263 25 Compiler messages ................................ 269 Index ........................................... 283 vi Contents I A brief overview of Aldor 1 1 Introduction 3 1.1 What is Aldor? .................................. 3 1.2 Compiling and running a single file ....................... 4 1.3 This guide ..................................... 6 1.4 Reporting problems ................................ 7 2 Some simple programs 9 2.1 Doubling integers ................................. 9 2.2 Square roots .................................... 10 2.3 A loop and output ................................ 11 2.4 Forming a type .................................. 13 2.5 Continuing ... ................................... 17 II The Aldor programming language 19 3 Language orientation 21 3.1 Traditional and non-traditional aspects ..................... 21 3.2 Expressions and evaluation ........................... 22 3.3 Functions ..................................... 23 3.4 Domains ...................................... 23 3.5 Compilation .................................... 23 3.6 Libraries ...................................... 24 4 Basic syntax 25 4.1 Syntax components ................................ 25 vii 4.2 Escape character ................................. 26 4.3 Keywords ..................................... 26 4.4 Names: identifiers and operators ........................ 27 4.5 Comments and descriptions ........................... 28 4.6 Application syntax ................................ 30 4.7 Grouping ..................................... 31 4.8 Piles ........................................ 34 5 Expressions 37 5.1 Names ....................................... 37 5.2 Literals ...................................... 38 5.3 Definitions ..................................... 40 5.4 Assignments .................................... 41 5.5 Functions ..................................... 42 5.6 Function calls ................................... 42 5.7 Imperatives .................................... 43 5.8 Multiple values .................................. 43 5.9 Sequences ..................................... 44 5.10 Exits ........................................ 45 5.11 If .......................................... 47 5.12 Select ....................................... 48 5.13 Logical expressions ................................ 48 5.14 Loops ......................................