ebook img

Common LISP. The Language. Second Edition PDF

1096 Pages·1990·2.629 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Common LISP. The Language. Second Edition

Contents Preface (Second Edition) xi 2.3. Symbols 29 2.4. Lists and Conses 32 Acknowledgments (Second Edition) 2.5. Arrays 33 xiii 2.5.1. Vectors 35 Acknowledgments(FirstEdition) xvii 2.5.2. Strings 36 2.5.3. Bit-Vectors 37 1. Introduction 1 2.6. Hash Tables 38 2.7. Readtables 38 1.1. Purpose 1 2.8. Packages 38 1.2. Notational Conventions 4 2.9. Pathnames 38 1.2.1. Decimal Numbers 4 2.10. Streams 38 1.2.2. Nil, False, and the Empty 2.11. Random-States 39 List 4 2.12. Structures 39 1.2.3. Evaluation, Expansion, and 2.13. Functions 39 Equivalence 5 2.14. Unreadable Data Objects 40 1.2.4. Errors 5 2.15. Overlap, Inclusion, and 1.2.5. Descriptions of Functions and Disjointness of Types 41 Other Entities 6 1.2.6. The Lisp Reader 10 1.2.7. Overview of Syntax 10 3. Scope and Extent 46 2. Data Types 13 4. Type Specifiers 53 2.1. Numbers 16 2.1.1. Integers 17 4.1. Type Speci(cid:12)er Symbols 53 2.1.2. Ratios 19 4.2. Type Speci(cid:12)er Lists 53 2.1.3. Floating-Point Numbers 20 4.3. Predicating Type 2.1.4. Complex Numbers 24 Speci(cid:12)ers 55 2.2. Characters 24 4.4. Type Speci(cid:12)ers That 2.2.1. Standard Characters 25 Combine 55 2.2.2. Line Divisions 26 4.5. Type Speci(cid:12)ers That 2.2.3. Non-standard Characters 27 Specialize 57 2.2.4. Character Attributes 28 4.6. Type Speci(cid:12)ers That 2.2.5. String Characters 28 Abbreviate 64 v vi CONTENTS 4.7. De(cid:12)ning New Type 7.8. Iteration 172 Speci(cid:12)ers 66 7.8.1. Inde(cid:12)nite Iteration 172 4.8. Type Conversion Function 68 7.8.2. General Iteration 173 4.9. Determining the Type of an 7.8.3. Simple Iteration Object 70 Constructs 178 4.10. Type Upgrading 72 7.8.4. Mapping 180 7.8.5. The \Program Feature" 183 5. Program Structure 73 7.9. Structure Traversal and Side Effects 188 5.1. Forms 73 7.10. Multiple Values 189 5.1.1. Self-Evaluating Forms 74 7.10.1. Constructs for Handling 5.1.2. Variables 74 Multiple Values 190 5.1.3. Special Forms 76 7.10.2. Rules Governing the Passing of 5.1.4. Macros 78 Multiple Values 195 5.1.5. Function Calls 79 7.11. Dynamic Non-Local Exits 198 5.2. Functions 79 5.2.1. Named Functions 80 5.2.2. Lambda-Expressions 80 8. Macros 205 5.3. Top-Level Forms 88 8.1. Macro De(cid:12)nition 206 5.3.1. De(cid:12)ning Named Functions 90 8.2. Macro Expansion 215 5.3.2. Declaring Global Variables and 8.3. Destructuring 217 Named Constants 92 8.4. Compiler Macros 217 5.3.3. Control of Time of 8.5. Environments 220 Evaluation 94 9. Declarations 228 6. Predicates 101 9.1. Declaration Syntax 228 6.1. Logical Values 102 9.2. Declaration Speci(cid:12)ers 237 6.2. Data Type Predicates 102 9.3. Type Declaration for 6.2.1. General Type Predicates 102 Forms 252 6.2.2. Speci(cid:12)c Data Type Predicates 105 10. Symbols 254 6.3. Equality Predicates 110 6.4. Logical Operators 116 10.1. The Property List 254 10.2. The Print Name 259 7. Control Structure 119 10.3. Creating Symbols 260 7.1. Constants and Variables 120 11. Packages 264 7.1.1. Reference 120 7.1.2. Assignment 127 11.1. Consistency Rules 266 7.2. Generalized Variables 129 11.2. Package Names 266 7.3. Function Invocation 154 11.3. Translating Strings to 7.4. Simple Sequencing 155 Symbols 268 7.5. Establishing New Variable 11.4. Exporting and Importing Bindings 157 Symbols 270 7.6. Conditionals 165 11.5. Name Con(cid:13)icts 272 7.7. Blocks and Exits 170 11.6. Built-in Packages 275 CONTENTS vii 11.7. Package System Functions and 14.2. Concatenating, Mapping, and Variables 279 Reducing Sequences 421 11.8. Modules 295 14.3. Modifying Sequences 426 11.9. An Example 296 14.4. Searching Sequences for Items 432 14.5. Sorting and Merging 436 12. Numbers 307 12.1. Precision, Contagion, and 15. Lists 440 Coercion 308 12.2. Predicates on Numbers 312 15.1. Conses 440 12.3. Comparisons on Numbers 313 15.2. Lists 442 12.4. Arithmetic Operations 315 15.3. Alteration of List 12.5. Irrational and Transcendental Structure 453 Functions 319 15.4. Substitution of 12.5.1. Exponential and Logarithmic Expressions 455 Functions 320 15.5. Using Lists as Sets 457 12.5.2. Trigonometric and Related 15.6. Association Lists 463 Functions 323 12.5.3. Branch Cuts, Principal Values, 16. Hash Tables 468 and Boundary Conditions in the Complex Plane 332 16.1. Hash Table Functions 469 12.6. Type Conversions and 16.2. Primitive Hash Function 475 Component Extractions on Numbers 375 17. Arrays 476 12.7. Logical Operations on Numbers 382 17.1. Array Creation 476 12.8. Byte Manipulation 17.2. Array Access 481 Functions 388 17.3. Array Information 482 12.9. Random Numbers 391 17.4. Functions on Arrays of 12.10. Implementation Bits 487 Parameters 394 17.5. Fill Pointers 489 17.6. Changing the Dimensions of an Array 490 13. Characters 398 13.1. Character Attributes 401 18. Strings 495 13.2. Predicates on Characters 403 13.3. Character Construction and 18.1. String Access 496 Selection 409 18.2. String Comparison 496 13.4. Character Conversions 410 18.3. String Construction and 13.5. Character Control-Bit Manipulation 499 Functions 413 19. Structures 504 14. Sequences 415 19.1. Introduction to 14.1. Simple Sequence Structures 504 Functions 419 19.2. How to Use Defstruct 506 viii CONTENTS 19.3. Using the Automatically 22.3.1. Output to Character De(cid:12)ned Constructor Streams 623 Function 510 22.3.2. Output to Binary 19.4. Defstruct Slot-Options 512 Streams 627 19.5. Defstruct Options 513 22.3.3. Formatted Output to 19.6. By-Position Constructor Character Streams 627 Functions 519 22.4. Querying the User 659 19.7. Structures of Explicitly Speci(cid:12)ed Representational 23. File System Interface 661 Type 523 23.1. File Names 661 19.7.1. Unnamed Structures 523 23.1.1. Pathnames 662 19.7.2. Named Structures 524 23.1.2. Case Conventions 668 19.7.3. Other Aspects of Explicitly 23.1.3. Structured Directories 672 Speci(cid:12)ed Structures 526 23.1.4. Extended Wildcards 675 23.1.5. Logical Pathnames 681 20. The Evaluator 528 23.1.5.1. Syntax of Logical Pathname 20.1. Run-Time Evaluation of Namestrings 681 Forms 528 23.1.5.2. Parsing of Logical Pathname 20.2. The Top-Level Loop 532 Namestrings 682 23.1.5.3. Using Logical 21. Streams 535 Pathnames 683 23.1.5.4. Examples of the Use of 21.1. Standard Streams 535 Logical Pathnames 686 21.2. Creating New Streams 538 23.1.5.5. Discussion of Logical 21.3. Operations on Streams 542 Pathnames 688 23.1.6. Pathname Functions 690 22. Input/Output 547 23.2. Opening and Closing 22.1. Printed Representation of Lisp Files 700 Objects 547 23.3. Renaming, Deleting, and Other 22.1.1. What the Read Function File Operations 707 Accepts 548 23.4. Loading Files 712 22.1.2. Parsing of Numbers and 23.5. Accessing Directories 718 Symbols 554 22.1.3. Macro Characters 563 24. Errors 720 22.1.4. Standard Dispatching Macro 24.1. General Error-Signaling Character Syntax 570 Functions 721 22.1.5. The Readtable 582 24.2. Specialized Error-Signaling 22.1.6. What the Print Function Forms and Macros 726 Produces 593 24.3. Special Forms for Exhaustive 22.2. Input Functions 611 Case Analysis 729 22.2.1. Input from Character Streams 611 25. Miscellaneous Features 732 22.2.2. Input from Binary Streams 622 25.1. The Compiler 732 22.3. Output Functions 622 25.1.1. Compiler Diagnostics 740 CONTENTS ix 25.1.2. Compiled Functions 741 28. Common Lisp Object 25.1.3. Compilation Environment 742 System 831 25.1.4. Similarity of Constants 747 28.1. Programmer Interface 25.2. Documentation 751 Concepts 831 25.3. Debugging Tools 752 28.1.1. Error Terminology 832 25.4. Environment Inquiries 759 28.1.2. Classes 835 25.4.1. Time Functions 759 28.1.2.1. De(cid:12)ning Classes 836 25.4.2. Other Environment 28.1.2.2. Creating Instances of Inquiries 763 Classes 837 25.5. Identity Function 765 28.1.2.3. Slots 837 28.1.2.4. Accessing Slots 839 26. Loop 767 28.1.3. Inheritance 841 28.1.3.1. Inheritance of Methods 841 26.1. Introduction 767 28.1.3.2. Inheritance of Slots and Slot 26.2. How the Loop Facility Options 841 Works 767 28.1.3.3. Inheritance of Class 26.3. Parsing Loop Clauses 768 Options 843 26.3.1. Order of Execution 769 28.1.3.4. Examples 843 26.3.2. Kinds of Loop Clauses 770 28.1.4. Integrating Types and 26.3.3. Loop Syntax 773 Classes 843 26.4. User Extensibility 773 26.5. Loop Constructs 773 28.1.5. Determining the Class 26.6. Iteration Control 774 Precedence List 845 26.7. End-Test Control 785 28.1.5.1. Topological Sorting 848 26.8. Value Accumulation 789 28.1.5.2. Examples 848 26.9. Variable Initializations 795 28.1.6. Generic Functions and 26.10. Conditional Execution 798 Methods 851 26.11. Unconditional Execution 800 28.1.6.1. Introduction to Generic 26.12. Miscellaneous Features 802 Functions 851 26.12.1. Data Types 802 28.1.6.2. Introduction to 26.12.2. Destructuring 803 Methods 852 28.1.6.3. Agreement on Parameter SpecializersandQuali(cid:12)ers 855 27. Pretty Printing 808 28.1.6.4. Congruent Lambda-Lists for 27.1. Introduction 808 All Methods of a 27.2. Pretty Printing Control Generic Function 856 Variables 809 28.1.6.5. Keyword Arguments in 27.3. Dynamic Control of the Generic Functions and Arrangement of Output 810 Methods 856 27.4. Format Directive 28.1.7. Method Selection and Interface 822 Combination 858 27.5. Compiling Format Control 28.1.7.1. Determining the Effective Strings 825 Method 858 27.6. Pretty Printing Dispatch 28.1.7.2. Standard Method Tables 826 Combination 861 x CONTENTS 28.1.7.3. Declarative Method 29. Conditions 939 Combination 863 29.1. Introduction 939 28.1.7.4. Built-in Method Combination 29.2. Changes in Terminology 941 Types 863 29.3. Survey of Concepts 942 28.1.8. Meta-objects 865 29.3.1. Signaling Errors 942 28.1.8.1. Metaclasses 866 29.3.2. Trapping Errors 944 28.1.8.2. Standard Metaclasses 866 29.3.3. Handling Conditions 946 28.1.8.3. Standard Meta-objects 866 29.3.4. Object-Oriented Basis of 28.1.9. Object Creation and Condition Handling 947 Initialization 867 29.3.5. Restarts 949 28.1.9.1. Initialization 29.3.6. Anonymous Restarts 949 Arguments 868 29.3.7. Named Restarts 951 28.1.9.2. Declaring the Validity of 29.3.8. Restart Functions 952 Initialization Arguments 869 29.3.9. Comparison of Restarts and 28.1.9.3. Defaulting of Initialization Catch/Throw 953 Arguments 870 29.3.10. Generalized Restarts 955 28.1.9.4. Rules for Initialization 29.3.11. Interactive Condition Arguments 871 Handling 956 29.3.12. Serious Conditions 956 28.1.9.5. Shared-Initialize 873 29.3.13. Non-Serious Conditions 957 28.1.9.6. Initialize-Instance 874 29.3.14. Condition Types 957 28.1.9.7. De(cid:12)nitions of Make-Instance 29.3.15. Signaling Conditions 958 and Initialize-Instance 876 29.3.16. Resignaling Conditions 959 28.1.10. Rede(cid:12)ning Classes 878 29.3.17. Condition Handlers 959 28.1.10.1. Modifying the Structure of 29.3.18. Printing Conditions 960 Instances 879 29.4. Program Interface to the 28.1.10.2. Initializing Newly Added Condition System 961 Local Slots 879 29.4.1. Signaling Conditions 961 28.1.10.3. Customizing Class 29.4.2. Assertions 964 Rede(cid:12)nition 880 29.4.3. Exhaustive Case Analysis 968 28.1.10.4. Extensions 880 29.4.4. Handling Conditions 970 28.1.11. Changing the Class of an 29.4.5. De(cid:12)ning Conditions 974 Instance 881 29.4.6. Creating Conditions 977 28.1.11.1. Modifying the Structure of 29.4.7. Establishing Restarts 978 an Instance 881 29.4.8. Finding and Manipulating 28.1.11.2. Initializing Newly Added Restarts 987 Local Slots 881 29.4.9. Warnings 989 28.1.11.3. Customizing the Change of 29.4.10. Restart Functions 990 Class of an Instance 882 29.4.11. Debugging Utilities 992 28.1.12. Reinitializing an 29.5. Prede(cid:12)ned Condition Instance 882 Types 993 28.1.12.1. Customizing Reinitialization 884 Appendix A. Series 1001 28.2. Functions in the Programmer Interface 884 A.1. Introduction 1001 CONTENTS xi A.2. Series Functions 1003 A.2.1. Scanners 1004 A.2.2. Mapping 1008 A.2.3. Truncation and Other Simple Transducers 1011 A.2.4. Conditional and Other Complex Transducers 1013 A.2.5. Collectors 1017 A.2.6. Alteration of Series 1020 A.3. Optimization 1022 A.3.1. Basic Restrictions 1023 A.3.2. Constraint Cycles 1024 A.3.3. De(cid:12)ning New Series Functions 1027 A.3.4. Declarations 1028 A.4. Primitives 1030 Appendix B. Generators and Gatherers 1036 B.1. Introduction 1036 B.2. Generators 1037 B.3. Gatherers 1037 B.4. Discussion 1039 Appendix C. Backquote 1040 References 1053 Index of X3J13 Votes 1058 Other Indexes 1064 xii CONTENTS Preface SECOND EDITION Common Lisp has succeeded. Since publication of the (cid:12)rst edition of this bookin1984,manyimplementorshaveuseditasade factostandardforLisp implementation. Asaresult,itisnowmucheasiertoportlargeLispprograms fromoneimplementationtoanother. CommonLisphasprovedtobeauseful and stable platform for rapid prototyping and systems delivery in arti(cid:12)cial intelligence and other areas. With experience gained in using Common Lisp forsomanyapplications,implementorsfoundnoshortageofopportunitiesfor innovation. OneoftheimportantcharacteristicsofLispisitsgoodsupportfor experimental extension of the language; while Common Lisp has been stable, it has not stagnated. The1984de(cid:12)nitionofCommonLispwasimperfectandincomplete. Insome cases this was inadvertent: some odd boundary situation was overlooked and its consequences not speci(cid:12)ed, or different passages were in con(cid:13)ict, or some propertyofLispwassowell-knownandtraditionallyrelieduponthatIforgot to write it down. In other cases the informal committee that was de(cid:12)ning Common Lisp could not settle on a solution, and therefore agreed to leave some important aspect of the language unspeci(cid:12)ed rather than choose a less than satisfactory de(cid:12)nition. An example is error handling; 1984 Common Lisp had plenty of ways to signal errors but no way for a program to trap or process them. Over the next year I collected reports of errors in the book and gaps in the language. In December 1985, a group of implementors and users met in Boston to discuss the state of Common Lisp. I prepared two lists for this meeting, one of errata and clari(cid:12)cations that I thought would be relatively uncontroversial (boy, was I wrong!) and one of more substantial changes I thought should be considered and perhaps voted upon. Others also brought proposals to discuss. It became clear to everyone that there was now enough interestinCommonLisp, anddependenceonitsstability, thatamoreformal mechanism was needed for managing changes to the language. xiii xiv PREFACE (SECOND EDITION) This realization led to the formation of X3J13, a subcommittee of ANSI committeeX3,toproduceaformalAmericanNationalStandardforCommon Lisp. That process is nearing completion. X3J13 has completed the bulk of its technical work in rectifying the 1984 de(cid:12)nition and codifying extensions to that de(cid:12)nition that have received widespread use and approval. A draft standard is now being prepared; it will probably be available in 1990. There will then be a period (required by ANSI) for public review. X3J13 must then considerthecommentsitreceivesandrespondappropriately. Ifthecomments result in substantial changes to the draft standard, multiple public review periods may be required before the draft can be approved as an American National Standard. Fortunately, X3J13 has done an outstanding job of documenting its work. For every change that came to a formal vote, a document was prepared that described the problem to be solved and one or more solutions. For each solutionthereisadetailedproposalforchangingthelanguage;arationale;test casesthatdistinguishtheproposalfromthestatusquoorfromotherproposals forsolvingthatproblem;discussionsofcurrentpractice,costtoimplementors, costtousers,costofnotadoptingtheproposal,bene(cid:12)tsofadoption,aesthetic criteria;andanyrelevantinformaldiscussionthatmayhaveprecededcreation of the formal proposal. All of these proposal documents were made available on-line as well as in paper form. By my count, by June 1989 some 186 such proposals were approved as language changes. (This count does not include many proposals that came before the committee but were rejected.) The purpose of this second edition is to bridge the gap between the (cid:12)rst editionandtheforthcomingANSIstandardforCommonLisp. Becauseofthe requirementforformalpublicreview,itwillbesometimeyetbeforetheANSI standard is (cid:12)nal. This book in no way resembles the forthcoming standard (which is being written independently by Kathy Chapman of Digital Equip- ment Corporation with assistance from the X3J13 Drafting Subcommittee). I have incorporated into this second edition a great deal of material based on the votes of X3J13, in order to give the reader a picture of where the language is heading. My purpose here is not simply to quote the X3J13 documentsverbatimbuttoparaphrasethemandrelatethemtothestructure of the (cid:12)rst edition. A single vote by X3J13 may be discussed in many parts of this book, and a single passage of this book may be affected by many of the votes. I wish to be very clear: this book is not an official document of X3J13, though it is based on publicly available material produced by X3J13. In no way does this book constitute a de(cid:12)nitive description of the forthcoming ANSI standard. The committee’s decisions have been remarkably stable (it

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.