Ada Distilled by Richard Riehle

Total Page:16

File Type:pdf, Size:1020Kb

Ada Distilled by Richard Riehle Ada Distilled by Richard Riehle An Introduction to Ada Programming for Experienced Computer Programmers by Richard Riehle AdaWorks Software Engineering http://www.adaworks.com Copyright 2002, AdaWorks Software Engineering Public Edition. Permission to copy if AdaWorks is acknowledged in copies Version: July 2003 Page 1 of 113 Ada Distilled by Richard Riehle Acknowledgments There are always a lot of people involved in the creation of any book, even one as small and modest as this one. Those who have contributed to the best features of this book include my students at Naval Postgraduate School, Mr. Michael Berenato of Computer Sciences Corporation, Mr. Ed Colbert of Absolute Software, and many students from Lockheed-Martin Corporation, Computer Sciences Corporation, British Aerospace, various branches of the uniformed services, to name a few. I also owe a special thanks to Dr. Ben Brosgol, Dr. Robert Dewar, Mr. Mark Gerhardt, and Dr. Mantak Shing for what I have learned from them. Also thanks to the contributors to comp.lang.ada Usenet forum and the Team_Ada Listserve. Phil Thornley deserves extra credit for his detailed reading of the manuscript and many corrections. Special thanks goes to Ed Colbert for his careful study of some of my program examples. He is one of those people who can spot a program error at fifty paces. Using this unique skill, Ed brought many errors, some big and some small, to my attention. Also thanks to more recent input from Phil Thornley and Adrian Hoe. Any other errors are strictly mine. Any mistakes in wording, spelling, or facts are mine and mine alone. I hope this book will be valuable to the intended audience. It is moderate in its intent: help the beginning Ada programmer get a good start with some useful examples of working code. More advanced books are listed in the bibliography. The serious student should also have one of those books at hand when starting in on a real project. Richard Riehle Intended Audience for this Book This book is aimed at experienced programmers who want to learn Ada at the programming level. It is not a "...for dummies" book, nor is it intended as a program design book. Instead, we highlight some key features of the Ada language, with coded examples, that are essential for getting started as an Ada programmer. Ada is a rich and flexibile language used for designing large-scale software systems. This book emphasizes syntax, control structures, subprogram rules, and how-to coding issues rather than design issues. There are other really fine books available that deal with design. Also, this is not a comprehensive treatment of the Ada language. The bibliography lists some books that can help you once you have finished the material in this book. Think of this a quick-start book, one that enables you, the experienced programmer, to get into the Ada language quickly and easily. The examples use text-oriented programs for simplicity of learning. If you prefer to do the exercises for a GUI environment, check out the sites listed for compilers and tools so you can download bindings for programming in a variety of windowing environments, including Wintel, Linux, and Unix. Of particular interest to those wanting to explore Window style programming are GtkAda, CLAW, GWindows, and JEWL. The last of these, JEWL, is especially useful if you have no prior experience writing Windows programs. Happy Coding, Richard Riehle Page 2 of 113 Ada Distilled by Richard Riehle Table of Contents TABLE OF CONTENTS............................................................................................................................. 3 1. WHAT IS ADA DISTILLED? ................................................................................................................ 4 2. SUMMARY OF LANGUAGE................................................................................................................ 5 3. TYPES AND THE TYPE MODEL ...................................................................................................... 16 4. CONTROL STRUCTURES FOR ALGORITHMS............................................................................ 26 5. ACCESS TYPES (POINTERS) ............................................................................................................ 33 6. SUBPROGRAMS................................................................................................................................... 40 7. PACKAGE DESIGN.............................................................................................................................. 47 8. CHILD LIBRARY UNITS .................................................................................................................... 52 9. OBJECT-ORIENTED PROGRAMMING WITH PACKAGES....................................................... 57 10. USING STANDARD LIBRARIES AND ANNEXES ....................................................................... 64 11. EXCEPTION MANAGEMENT........................................................................................................ 71 12. GENERIC COMPONENTS................................................................................................................ 74 13. NEW NAMES FROM OLD ONES .................................................................................................... 82 14. CONCURRENCY WITH TASKING................................................................................................. 87 A. ANNEXES, APPENDICES AND STANDARD LIBRARIES.......................................................... 92 ANNEX L PRAGMAS - LANGUAGE-DEFINED COMPILER DIRECTIVES............................... 104 WINDOWS 95/98/NT/XP/ME/2000 PROGRAMMING ...................................................................... 105 C. BIBLIOGRAPHY............................................................................................................................... 107 Author's Observation and Opinion The Ada language is designed to maximize the possibilities for error detection early in the development process. This reduces the overall cost of software development since it is known that errors corrected early, will cost less than those detected late. No other language, not C++, not Java, not Eiffel, provides the level of support for safety-critical software found in Ada. Developers can and do make mistakes, even using Ada, but the probability of such mistakes is substantially less when using Ada than it is when using other languages. Therefore, when failure is not acceptable, during development or during software execution, the wise developer will select Ada. Although Ada is not as popular as some of the more well-known languages, it has substantial benefits over most of them when software dependability is a primary objective. In addition, contemporary Ada is as appropriate for developing GUI-based applications, information systems applications, and computationally intensive systems as any existing language. It is truly a general-purpose language, well-suited to any kind of software problem you might encounter. Page 3 of 113 Ada Distilled by Richard Riehle 1. What is Ada Distilled? This book is for experienced programmers new to Ada. Heavily commented example programs help experienced programmer experiment with Ada. This is not a comprehensive book on the entire Ada language. In particular, we say very little about Ada.Finalization, Storage Pool Management, Representation Specifications, Concurrency, and other more advanced topics. Other books, listed in the bibliography, cover advanced topics. This book is an entry point to your study of Ada. The text is organized around example programs with line-by-line comments. Ada comments are the double-hyphen and continue to the end of a line. Comments might be explanatory notes and/or corresponding section of the Ada Language Reference Manual (ALRM) in the format of ALRM X.5.3/22. with Ada.Text_IO; -- 1 10.1.2, A.10 Context clause A hello program in Ada. This will compile procedure Hello is -- 2 6.3 Specification with "is" and execute with begin -- 3 6.3 Start algorithmic code any Ada compiler. Ada.Text_IO.Put_Line(“Hello Ada”); -- 4 A.10.6 Executable source code end Hello; -- 5 6.3 End of procedure scope where each line is numbered. The 10.1.2 and 6.3, etc. refer to ALRM Chapters 6.3, 10.1.2. A.10.6 refers to Annex A.10.6. There is occasional commentary by source code line number. The line numbers are not part of Ada, but provided on our examples for ease of commentary. Boxed notes are also included for some examples. The preceding example shows one of these as: 1.1 Ada Compilers and Tools Ada 95 compilers support a wide range of platforms. A free, open source, compiler, GNAT, based on GNU technology, can be downloaded from the Web. Commercial Ada compilers and tools are available from: Ada Core Technologies (GNAT), DDC-I, Rational (recently acquired by IBM), RR Software, Irvine Compiler Corporation, Green Hills, SofCheck, Aonix, and OC Systems. Free editors, including AdaGide, are useful for developing small Ada programs. More information on tools, including GUI development tools, can be accessed using one of the URL's mentioned in the introduction and in the bibliography. Development tools exist for many operating systems. These include CLAW for Microsoft Operating Systems, and GtkAda for other GUI environments including Microsoft operating systems, Linux, BSD, OS/2, Java Virtual Machine, and every variety of Unix. The AdaGide editor is available for MS Windows. 1.2 Ada Education The bibliography of this book
Recommended publications
  • SETL for Internet Data Processing
    SETL for Internet Data Processing by David Bacon A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy Computer Science New York University January, 2000 Jacob T. Schwartz (Dissertation Advisor) c David Bacon, 1999 Permission to reproduce this work in whole or in part for non-commercial purposes is hereby granted, provided that this notice and the reference http://www.cs.nyu.edu/bacon/phd-thesis/ remain prominently attached to the copied text. Excerpts less than one PostScript page long may be quoted without the requirement to include this notice, but must attach a bibliographic citation that mentions the author’s name, the title and year of this disser- tation, and New York University. For my children ii Acknowledgments First of all, I would like to thank my advisor, Jack Schwartz, for his support and encour- agement. I am also grateful to Ed Schonberg and Robert Dewar for many interesting and helpful discussions, particularly during my early days at NYU. Terry Boult (of Lehigh University) and Richard Wallace have contributed materially to my later work on SETL through grants from the NSF and from ARPA. Finally, I am indebted to my parents, who gave me the strength and will to bring this labor of love to what I hope will be a propitious beginning. iii Preface Colin Broughton, a colleague in Edmonton, Canada, first made me aware of SETL in 1980, when he saw the heavy use I was making of associative tables in SPITBOL for data processing in a protein X-ray crystallography laboratory.
    [Show full text]
  • Modern Programming Languages CS508 Virtual University of Pakistan
    Modern Programming Languages (CS508) VU Modern Programming Languages CS508 Virtual University of Pakistan Leaders in Education Technology 1 © Copyright Virtual University of Pakistan Modern Programming Languages (CS508) VU TABLE of CONTENTS Course Objectives...........................................................................................................................4 Introduction and Historical Background (Lecture 1-8)..............................................................5 Language Evaluation Criterion.....................................................................................................6 Language Evaluation Criterion...................................................................................................15 An Introduction to SNOBOL (Lecture 9-12).............................................................................32 Ada Programming Language: An Introduction (Lecture 13-17).............................................45 LISP Programming Language: An Introduction (Lecture 18-21)...........................................63 PROLOG - Programming in Logic (Lecture 22-26) .................................................................77 Java Programming Language (Lecture 27-30)..........................................................................92 C# Programming Language (Lecture 31-34) ...........................................................................111 PHP – Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)........................129 Modern Programming Languages-JavaScript
    [Show full text]
  • Preconditions/Postconditions Author: Robert Dewar Abstract: Ada Gem
    Gem #31: preconditions/postconditions Author: Robert Dewar Abstract: Ada Gem #31 — The notion of preconditions and postconditions is an old one. A precondition is a condition that must be true before a section of code is executed, and a postcondition is a condition that must be true after the section of code is executed. Let’s get started… The notion of preconditions and postconditions is an old one. A precondition is a condition that must be true before a section of code is executed, and a postcondition is a condition that must be true after the section of code is executed. In the context we are talking about here, the section of code will always be a subprogram. Preconditions are conditions that must be guaranteed by the caller before the call, and postconditions are results guaranteed by the subprogram code itself. It is possible, using pragma Assert (as defined in Ada 2005, and as implemented in all versions of GNAT), to approximate run-time checks corresponding to preconditions and postconditions by placing assertion pragmas in the body of the subprogram, but there are several problems with that approach: 1. The assertions are not visible in the spec, and preconditions and postconditions are logically a part of (in fact, an important part of) the spec. 2. Postconditions have to be repeated at every exit point. 3. Postconditions often refer to the original value of a parameter on entry or the result of a function, and there is no easy way to do that in an assertion. The latest versions of GNAT implement two pragmas, Precondition and Postcondition, that deal with all three problems in a convenient way.
    [Show full text]
  • Understanding Programming Languages
    Understanding Programming Languages M. Ben-Ari Weizmann Institute of Science Originally published by John Wiley & Sons, Chichester, 1996. Copyright °c 2006 by M. Ben-Ari. You may download, display and print one copy for your personal use in non-commercial academic research and teaching. Instructors in non-commerical academic institutions may make one copy for each student in his/her class. All other rights reserved. In particular, posting this document on web sites is prohibited without the express permission of the author. Contents Preface xi I Introduction to Programming Languages 1 1 What Are Programming Languages? 2 1.1 The wrong question . 2 1.2 Imperative languages . 4 1.3 Data-oriented languages . 7 1.4 Object-oriented languages . 11 1.5 Non-imperative languages . 12 1.6 Standardization . 13 1.7 Computer architecture . 13 1.8 * Computability . 16 1.9 Exercises . 17 2 Elements of Programming Languages 18 2.1 Syntax . 18 2.2 * Semantics . 20 2.3 Data . 21 2.4 The assignment statement . 22 2.5 Type checking . 23 2.6 Control statements . 24 2.7 Subprograms . 24 2.8 Modules . 25 2.9 Exercises . 26 v Contents vi 3 Programming Environments 27 3.1 Editor . 28 3.2 Compiler . 28 3.3 Librarian . 30 3.4 Linker . 31 3.5 Loader . 32 3.6 Debugger . 32 3.7 Profiler . 33 3.8 Testing tools . 33 3.9 Configuration tools . 34 3.10 Interpreters . 34 3.11 The Java model . 35 3.12 Exercises . 37 II Essential Concepts 38 4 Elementary Data Types 39 4.1 Integer types .
    [Show full text]
  • CWI Scanprofile/PDF/300
    Centrum voor Wiskunde en lnformatica Centre for Mathematics and Computer Science L.G.L.T. Meertens, S. Pemberton An implementation of the B programming language Department of Computer Science Note CS-N8406 June Biblioiiie.:;I( ~'~'l'i't'Hm.n<' Wi~f.i;r;de- c11 !nform;:,;i:i.C<a - Ams1errJar11 AN IMPLEMENTATION OF THE B PROGRAMMING LANGUAGE L.G.L.T. MEERTENS, S. PEMBERTON CentPe foP Mathematics and ComputeP Science~ AmstePdam Bis a new programming language designed for personal computing. We describe some of the decisions taken in implementing the language, and the problems involved. Note: B is a working title until the language is finally frozen. Then it will acquire its definitive name. The language is entirely unrelated to the predecessor of C. A version of this paper will appear in the proceedings of the Washington USENIX Conference (January 1984). 1982 CR CATEGORIES: 69D44. KEY WORDS & PHRASES: programming language implementation, progrannning envi­ ronments, B. Note CS-N8406 Centre f~r Mathematics and Computer Science P.O. Box 4079, 1009 AB Amsterdam, The Netherlands I The programming language B B is a programming language being designed and implemented at the CWI. It was originally started in 1975 in an attempt to design a language for beginners as a suitable replacement for BASIC. While the emphasis of the project has in the intervening years shifted from "beginners" to "personal computing", the main design objectives have remained the same: · • simplicity; • suitability for conversational use; • availability of tools for structured programming. The design of the language has proceeded iteratively, and the language as it now stands is the third iteration of this process.
    [Show full text]
  • Art, Artist, and Witness(Ing) in Canada's Truth and Reconciliation
    Dance with us as you can…: Art, Artist, and Witness(ing) in Canada’s Truth and Reconciliation Journey by Jonathan Robert Dewar A thesis submitted to the Faculty of Graduate and Postdoctoral Affairs in partial fulfillment of the requirements for the degree of Doctor of Philosophy in Indigenous and Canadian Studies Carleton University Ottawa, Ontario © 2017, Jonathan Robert Dewar Abstract This dissertation explores, through in-depth interviews, the perspectives of artists and curators with regard to the question of the roles of art and artist – and the themes of community, responsibility, and practice – in truth, healing, and reconciliation during the early through late stages of the 2008-2015 mandate of the Truth and Reconciliation Commission of Canada (TRC), as its National Events, statement taking, and other programming began to play out across the country. The author presents the findings from these interviews alongside observations drawn from the unique positioning afforded to him through his professional work in healing and reconciliation-focused education and research roles at the Aboriginal Healing Foundation (2007-2012) and the Shingwauk Residential Schools Centre (2012-2016) about the ways art and artists were invoked and involved in the work of the TRC, alongside it, and/or in response to it. A chapter exploring Indigenous writing and reconciliation, with reference to the work of Basil Johnston, Jeannette Armstrong, Tomson Highway, Maria Campbell, Richard Wagamese, and many others, leads into three additional case studies. The first explores the challenges of exhibiting the legacies of Residential Schools, focusing on Jeff Thomas’ seminal curatorial work on the archival photograph-based exhibition Where Are the Children? Healing the Legacy of Residential Schools and Heather Igloliorte’s curatorial work on the exhibition ‘We were so far away…’: The Inuit Experience of Residential Schools, itself a response to feedback on Where Are the Children? Both examinations draw extensively from the author’s interviews with the curators.
    [Show full text]
  • AINSE Plasma Science and Technology
    AU94136G4 I AU9413768 AINSE Plasma Science and Technology C^onterence iNis-mf—13853 & Elizabeth and Frederick White Workshop on Fundamental Problems in the Physics of Magnetically Confined Plasmas Canberra 12-15 July 1993 Conference Handbook ISSN 08123357 AINSE Plasma Science and Technology Conference k Elizabeth and Frederick White Workshop on Fundamental Problems in the Physics of Magnetically Confined Plasmas Australian Academy of Science Canberra 12-15 July, 1993 The Conference Committee Prof R L Dewar President Australian National University Dr H J Gardner Secretary Australian National University Prof S M Hamberger Australian National University Dr R W Boswell Australian National University Dr L E Sharp Australian National University Dr B Luther-Davies Australian National University Dr A Cheetham University of Canberra A/Prof J A Lehane University of Sydney Dr R Gammon AINSE Dr IJ Donnelly ANSTO Invited Speakers Prof Amitava Bhattacharjee University of Iowa Prof John Cary University of Colorado, Boulder Prof Liu Chen University of California, Irvine Dr Anthony Cooper EPFL, Switzerland Prof Peter Dyson La Trobe University Dr Barry Green ITER Joint Central Team, Naka, Japan Dr John Keller IBM, East Fishkill, New York Dr Hajime Kuwahara Nissin Electric, Kyoto Dr John Lowke CSIRO Division of Applied Physics Dr V Petrzilka Czech Academy of Science, Prague Dr S Ramakrishnan CSIRO Division of Manufacturing Technology Prof Alfred Wong University of California, Los Angeles The Conference Committee gratefully acknowledges the support of the Elizabeth and Frederick White Research Conference Fund of the Australian Academy of Science and the support of the Australian Institute of Nuclear Science and Engineering. This is the 19th AINSE Plasma Physics conference.
    [Show full text]
  • Oral History Interview with Robert Goldberg
    An Interview with ROBERT GOLDBERG OH 207 Conducted by David S. Cargo on 27 July 1990 Flagstaff, AZ Charles Babbage Institute Center for the History of Information Processing University of Minnesota, Minneapolis 1 Robert Goldberg Interview 27 July 1990 Abstract Goldberg describes his use of Icon in the classroom at Illinois Institute of Technology and emphasizes the strength of Icon for instructional purposes over other programming languages. He discusses his interaction with Ralph Griswold when working on the various implementations of Icon. Goldberg describes the strong documentation produced by the Icon project and his own work on conversion of Icon from a UNIX to a VAS VMS implementation. He discusses the development of a PC version of Icon and his own use of Icon in normal work. 2 ROBERT GOLDBERG INTERVIEW DATE: July 27, 1990 INTERVIEWER: David S. Cargo LOCATION: Flagstaff, AZ CARGO: Okay, Bob, why don't you tell me about your educational background prior to the time that you got involved with Icon. GOLDBERG: I have a bachelor's degree in mathematics and computer science from the University of Illinois at Urbana. I have a master's degree in computer science from Illinois Institute of Technology in Chicago. CARGO: Could you give me a couple of dates for those? GOLDBERG: Bachelor's degree - 1973; master's degree - 1977. Since that time I have taught part-time at IIT. And I think my title, at this point, is adjunct assistant professor. I typically teach one course a semester. And one of the reasons that I went to IIT is that I became a SNOBOL aficionado when I was at the University of Illinois, I ended up at IIT because of Robert Dewar, who had done SPITBOL, and I worked with him while he was at IIT.
    [Show full text]
  • Maritime Hunter-Gatherers: Ecology and Prehistory [And Comments and Reply] Author(S): David R
    Maritime Hunter-Gatherers: Ecology and Prehistory [and Comments and Reply] Author(s): David R. Yesner, William S. Ayres, David L. Carlson, Richard S. Davis, Robert Dewar, Manuel R. González Morales, Fekri A. Hassan, Brian Hayden, Joseph J. Lischka, Payson D. Sheets, Alan Osborn, David L. Pokotylo, Tom Rogers, Ehud Spanier, B. L. Turner II and Ernst E. Wreschner Source: Current Anthropology , Dec., 1980, Vol. 21, No. 6 (Dec., 1980), pp. 727-750 Published by: The University of Chicago Press on behalf of Wenner-Gren Foundation for Anthropological Research Stable URL: http://www.jstor.com/stable/2742514 JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide range of content in a trusted digital archive. We use information technology and tools to increase productivity and facilitate new forms of scholarship. For more information about JSTOR, please contact [email protected]. Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at https://about.jstor.org/terms The University of Chicago Press and Wenner-Gren Foundation for Anthropological Research are collaborating with JSTOR to digitize, preserve and extend access to Current Anthropology This content downloaded from 128.227.24.141 on Mon, 31 Aug 2020 19:17:52 UTC All use subject to https://about.jstor.org/terms CURRENT ANTHROPOLOGY Vol. 21, No. 6, December 1980 ? 1980 by The Wenner-Gren Foundation for Anthropological Research 0011-3204/80/2106-0003$02.75 Maritime Hunter-Gatherers: Ecology and Prehistory' by David R. Yesner HUNTER-GATHERERS: ECOLOGY, DEMOGRAPHY, maintained below average "carrying capacity" through a mix SOCIAL ORGANIZATION of biological and social regulators.
    [Show full text]
  • (Pdf) of the School of Squiggol: a History of the Bird−Meertens
    The School of Squiggol A History of the Bird{Meertens Formalism Jeremy Gibbons University of Oxford Abstract. The Bird{Meertens Formalism, colloquially known as \Squig- gol", is a calculus for program transformation by equational reasoning in a function style, developed by Richard Bird and Lambert Meertens and other members of IFIP Working Group 2.1 for about two decades from the mid 1970s. One particular characteristic of the development of the Formalism is fluctuating emphasis on novel `squiggly' notation: sometimes favouring notational exploration in the quest for conciseness and precision, and sometimes reverting to simpler and more rigid nota- tional conventions in the interests of accessibility. This paper explores that historical ebb and flow. 1 Introduction In 1962, IFIP formed Working Group 2.1 to design a successor to the seminal algorithmic language Algol 60 [4]. WG2.1 eventually produced the specification for Algol 68 [63, 64]|a sophisticated language, presented using an elaborate two- level description notation, which received a mixed reception. WG2.1 continues to this day; technically, it retains responsibility for the Algol languages, but practi- cally it takes on a broader remit under the current name Algorithmic Languages and Calculi. Over the years, the Group has been through periods of focus and periods of diversity. But after the Algol 68 project, the period of sharpest focus covered the two decades from the mid 1970s to the early 1990s, when what later became known as the Bird{Meertens Formalism (BMF) drew the whole group together again. It is the story of those years that is the subject of this paper.
    [Show full text]
  • AP 20 Pages-Rc
    Your gateway to Ada– the right choice for reliable software Tri-Ada’97 CONFERENCE The annual meeting of the Ada programming world Adam’s Mark Hotel, St. Louis, Missouri November 9 - 13, 1997 FINAL PROGRAM TM Tri-Ada '97 is presented in cooperation with ACM SIGSOFT, SIGPLAN, SIGCSE and Ada Europe. A Message From the TRI-Ada ’97 Conference Committee Conference Chair In an annual tradition of some standing, members of General Chair the government, industry, and academic communities have David F. Harrison come together for a forum of discussions, presentations, Harris Technical Services Corporation workshops, panels, vendor presentations, and informal meetings, of which the principal focus has been Ada. For the past eleven years, these conferences have been known Program Chair as Tri-Ada, in keeping with their tri-partite constituencies. Norman H. Cohen The Tri-Ada ’97 conference is set to take place in St. IBM Thomas J. Watson Research Center Louis, MO, November 9-13, 1997. Once again, the confer- ence is sponsored by the ACM Special Interest Group for Ada, SIGAda. Also this year, Tri-Ada is being held in cooperation with three other ACM SIGs - SIGPLAN Registration Chair (Programming Languages), SIGSOFT (Software Engineering), and SIGCSE (Computer Ann C. McKenna Science Education) - and Ada Europe. Registration Manager This has been an eventful year for Ada. The 1996 National Research Council R.E. Abraham & Associates report on Defense Department programming language policy made several signifi- cant recommendations, which - upon implementation - have changed the way in Exhibits Chair which the language is viewed by the DoD, and the world.
    [Show full text]
  • “It All Started with ABC, a Wonderful Teaching Language That I Had Helped Create in the Early Eighties
    ABC language the mother of Python “It all started with ABC, a wonderful teaching language that I had helped create in the early eighties. It was an incredibly elegant and powerful language, aimed at non-professional programmers.” Guido van Rossum, ABC team member and creator of Python1 ABC 1.05 Python 3.2 SIEVE TO procedure definition >>> HOW TO SIEVE TO n: >>> def sieve(n): HOW TO SIEVE TO n: ... numbers = set(range(2, n+1)) PUT {2..n} IN numbers ... while numbers: condition must be a test WHILE numbers <> {}: ... p = min(numbers) PUT min numbers IN p ... print(p, end=' ') WRITE p ... for m in range(1, int(n/p)+1): FOR m IN {1..floor(n/p)}: ... if m*p in numbers: IF m*p in numbers: ... numbers.remove(m*p) REMOVE m*p FROM numbers 21 years later, Python still has a lot of ABC in it ... >>> sieve(50) >>> SIEVE TO 50 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 1. Foreword for "Programming Python" (1st ed.) http://www.python.org/doc/essays/foreword/ Basic Types Numbers Text ▪ Numbers are either exact or inexact. ▪ Mutable ASCII strings of arbitrary length. ▪ Exact numbers are stored as ratios of ▪ First character position is @ 1. integers of arbitrary length. ▪ Slicing is done with operators @ and | (pipe), ▪ Basic arithmetic (+, -, *, /) with exact see examples below. numbers always produce exact results. ABC 1.05 ▪ Some functions, such as root, sin, log etc.
    [Show full text]