Common Lisp Recipes

所需积分/C币:10 2017-10-20 17:09:09 8.95MB PDF
收藏 收藏 1

Common Lisp Recipes is a collection of solutions to problems and answers to questions you are likely to encounter when writing real-world applications in Common Lisp. Written by an author who has used Common Lisp in many successful commercial projects over more than a decade, this book is the first
Common Lisp Recipes: A Problem-Solution Approach Edmund weitz Hamburg germany ISBN13(pbk):978-1-4842-1177-9 ISBN-13( electronic:978-1-4842-1176-2 DOI:10.1007/978-1-4842-1176-2 Library of Congress Control Number: 2015960959 Copyright o 2016 by Edmund Weitz This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse ofillustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publishers location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark he use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein Managing Director: Welmoed Spahr Lead Editor: Steve anglin Technical reviewer: Hans hubner Editorial Board: Steve Anglin, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick Ben Renow-Clarke, Gwenan Spearing, Steve Weiss Coordinating Editor: Mark Powers Copy Editor: Kimberly burton-Weisman Compositor: SPi global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax(201)348-4505 e-mailorders-nyospringer-sbm.comorvisitwww.springeronline.comApressMedia,LlcisaCaliforniaLlc and the sole member(owner) is Springer Science+ Business Media Finance Inc(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation, Apress and friends of ed books may be purchased in bulk for academic, corporate, or promotional use e Book versions and licenses are also available for most titles. For more information, reference our Special bulk Any source code or other supplementary materials referenced by the author in this text is available to readers at Material section for each chapter Printed on acid-free paper For heike and mouna Table of contents about the author XVIL about the Technical reviewer XⅨX Preface XXI Who This book is for XXI Who This Book Is(Probably)Not For XX∏ How to read This book XXII What's In and what not .,,,,,,,,,,,.XXTI The hyperspec XXIV Which Implementation Source code XXV The Index XXV Typographical conventions XXV Acknowledgements 1. Symbols and Packages 1-1. Understanding the role of packages and the symbol nomenclature. 1 1-2. Making unique symbols 1-3. Making Symbols Inaccessible How Can We Fix This? 1-4. Avoiding Name Conflicts 12 When Name Conflicts do Not occur 15 1-5. Using Symbols as stand-Ins for Arbitrary forms 15 1-6. Searching for Symbols by Name 17 1-7. Iterating Through All Symbols of a Package 19 What To Do If You don t Like loop 20 1-8. Understanding COMMON LISP's Case(In)Sensitivity 21 Style hint: Dont Use CamelCase! 25 1-9. Using Symbols As String Substitutes 26 So, what Should You use? 27 1-10."Overloading"of Standard COMMON LISP Operators 28 2. Conses, Lists, and trees 31 2-1. Understanding Conses 31 List ace 34 Testing Whether Something Is a Cons or a list 35 22. Creating Lists..· 37 Converting Vectors to Lists 38 2-3. Transposing a Matrix 39 Table of contents 2-4. USing List Interpolation 2-5. Adding Objects to the End of a List 42 The Tail Wagging the list 44 2-6. Splicing" into a List 45 2-7. Detecting Shared Structure in Lists 49 Isolating the Non-Shared Part 51 2-8 orking with Trees .51 More Complicated Trees 54 COMMON LISP'S Standard Tree Functions 55 2-9. Working with Stacks 55 2-10. Implementing a queue 56 2-11. Destructuring and Pattern Matching 58 3. Strings and Characters ..61 3-1. Getting the asCll Code of a character The Other Way a round ..,,63 The limit 63 3-2. Naming Characters 63 3-3. USing Different Character Encodings 65 3-4. Comparing strings or Characters .,.,67 Internationalization 70 3-5. Escaping Characters in String Literals and Variable Interpolation Is It still a literal? 72 3-6. Controlling case What about Unicode? 74 3-7. Accessing or Modifying a Substring .75 3-8. Finding a Character or a Substring Within a String 77 3-9. Trimming strings 77 3-10. Processing a string one character at a time 79 3-11. Joining Strings 81 3-12. Reading csv Data 4. Numbers and math 87 4-1. USing Arbitrarily Large Integers ....87 4-2. Understanding Fixnums 89 4-3. Performing Modular Arithmetic 92 Efficiency Considerations 4-4. Switching Bases 94 4-5. Performing Exact Arithmetic with Rational numbers 96 Various Ways of Converting Numbers to Integers How Not to use floor and friends Converting Floating-Point Numbers to Rationals and Vice Versa 99 Mixing rationals and Floats ....101 4-6. Controlling the Default Float Format 102 4-7. Employing arbitrary precision Floats 104 4-8. Working with Complex numbers 106 Table of contents 4-9. Parsing numbers 4-10. Testing Whether Two Numbers Are Equal .111 Dont Ever use eQ with Numbers! 112 4-11. Computing Angles Correctly .113 4-12. Calculating exact Square roots 115 5. Arrays and Vectors 117 5-1. Working with Multiple Dimensions 117 5-2. Understanding vectors and Simple arrays ..,.119 5-3. Obtaining the Size of an Array .120 5-4. Providing Initial Contents 121 A Warning About Identical Objects 122 Treating Arrays As Vectors 123 Making the length of vectors Flexible 125 5-7. Adjusting arrays 127 5-8. USing an Array As a" Windowinto Another Array 129 5-9. Restricting the Element Type of an array .131 Upgrading Element Types 133 5-10. Copying an array 134 A Warning About Object Identity 135 6. Hash Tables, maps, and sets 137 6-1. Understanding the Basics of Hash Tables 137 Why Does GETHASH Return Two values 139 How Many Entries does the hash Table have? 140 6-2. Providing Default Values For Hash Table Lookups 140 6-3. Removing Hash Table entries .142 6-4. Iterating Through a Hash Table .143 Dont rely on any order 146 Don't Modify While You're Iterating 147 Cant This be more concise, please? 147 6-5. Understanding hash Table Tests and defining your own 148 What Is sXhash For? 152 6-6. Controlling Hash Table growth 152 6-7. Getting Rid of Hash Table Entries Automatically .155 6-8. Representing Maps As Association Lists 158 Combining Lookup and manipulation 161 Why Would Anybody Prefer Alists over Hash Tables? .... 162 6-9. Representing Maps As Property Lists 163 When to Prefer plists over Alists 165 The plist of a Symbol 166 6-10. Working with Sets 166 Representing sets As hash Tables 169 Representing sets as Bit Patterns 169 7. Sequences and iteration .171 7-1. Filtering a Sequence .....171 Table of contents 7-2. Searching a Sequence .172 7-3. Sorting and Merging Sequences 175 7-4. Mixing Different Sequence Types .177 7-5. Re-USing a Part of a Sequence ..177 7-6. Repeating some values cyclically .179 Alternatives ,...181 7-7. Counting down ....182 7-8. Iterating over" Chunks"of a List .184 7-9. Closing over Iteration Variables 186 7-10."Extending" Short Sequences in Iterations 187 7-11. Breaking out of LOOP 188 7-12. Making sense of the MAP... Zo The Sequence variants .194 7-13. Defining Your Own Sequence Types ....194 7-14. Iterating with ITERATE 196 7-15. Iterating with SERIES 200 What the Example does 201 8. The Lisp reade 203 8-1. Employing the Lisp reader for Your Own Code 203 Why read Is potentially dangerous 205 What rEAD Doesnt Do 205 The Optional arguments to READ 206 Go Wild! 206 8-2. Troubleshooting Literal Object Notation .206 This also Applies to Strings .208 8-3. Evaluating Forms at Read Time 208 What to look out for 210 Alternatives ..210 8-4. Embedding literal arrays into Your Code .,,.211 The Usual Warning .212 8-5. Understanding the Different Ways to Refer to a Function....... 213 8-6. Repeating Something You already Typed .,,214 They Dont Only Look Identical, They Are Identical 216 8-7. Safely Experimenting with readtables .216 Temporarily switching to Standard Io Syntax .218 8-8. Changing the Syntax Type of a Character .,..219 The Six Syntax Types 220 How to Actually Change the Syntax Type 222 Some Things Never Change 222 8-9. Creating Your Own Reader macros 223 What Reader macro functions do 224 8-10. Working with Dispatching Macro Characters 226 8-11. Preserving Whitespace 228 Table of contents Itin g 231 9-1. Using the printing primitives 231 Printing Objects So That They Can Be read Back in Again 235 Shortcuts 236 9-2. Printing to and into Strings 237 9-3. Printing NIL as a list 239 9-4. Extending FORMAT Control Strings Over More Than One line 240 9-5. USing Functions As FORMAT Controls 241 9-6. Creating Your Own FORMaT Directives .243 9-7. Recursive Processing of FORMAT Controls 245 9-8. Controlling How Your Own Objects Are Printed .247 9-9. Controlling the Pretty Printer 249 9-10. Printing Long lists 253 9-11. Pretty-Printing Compound objects 257 Using the Pretty printer from FORMAt 260 9-12. Modifying the Pretty Printer .262 10. Evaluation, Compilation, Control Flow 265 10-1. Comparing Arbitrary Lisp Objects .265 Comparing State 26 Constants 269 10-2. Using Constant Variables as Keys in CASE Macros 269 10-3. Using Arbitrary Variable Names for Keyword Parameters ..... 271 Keyword Names Don t have to be Keywords 272 Keyword Dames Dont have to Be Constant 273 10-4. Creating"Static Local Variables, "Like in C 273 10-5.Preponing the Computation of values 275 10-6. Modifying the behavior of functions You dont Have the Source of 278 10-7. Swapping the values of Variables(or Places 10-8. Creating Your Own \rte Forms for"Phgt∵… 280 283 Using DEFSETF 285 Using DEFINE-SETF-EXPANDER 286 So, Which one do i use? 291 Using DEFINE-MODIFY-MACRO .291 Multiple-valued places 293 10-9. Working with Environments 294 10-10. Commenting Out Parts of Your Code Some notes about and# 302 How; #I, and Others are lmplemented 302 11. Concurrency 303 11-1. Managing Lisp Processes .304 Escape Hatches 307 Threads Are expensive 308 1-2. Accessing Shared Resources Concurrently .308 Locks .312 X Table of contents Atomic Operations .313 More problems 314 11-3. Using Special Variables in Concurrent Programs .317 Per-Thread Initial Bindings ..319 Variables That Are Always Globa ...319 11-4. Communicating with Other Threads 320 Alternatives 11-5. Parallelizing Algorithms Without Threads and Locks 322 322 What the Example does 325 Fine-Tuning 326 Trees 326 Alternatives 330 11-6. Determining the Number of Cores 330 12. Error Handling and Avoidance 333 12-1. Checking Types at Run Time 333 Alternatiⅴes 335 12-2. Adding assertions to Your Code 336 Disabling Assertions in"Production Code 338 12-3. Defining Your Own Conditions .,..338 How Conditions are printed 340 12-4. Signaling a condition .341 Condition designators 343 12-5. Handling Conditions 344 Ignoring errors .349 12-6. Providing and Using Restarts 350 Visible restarts 354 Predefined restarts 355 12-7. Getting Rid of Warning Messages ..356 12-8. Protecting Code from Non-Local Exits 357 WITH-Macros .360 13. Objects, Classes, Types 361 13-1. Defining Types .,..361 Compound Type specifiers 363 Derived Types .365 13-2. Using Classes As Types .366 13-3. Writing Methods for Built-In Classes 367 13-4. Providing Constructors for Your Classes 369 13-5. Marking Slots As"Private 372 13-6. Changing the Argument Precedence Order ..374 13-7. Automatically Initializing Slots on First Usage ..376 13-8. Changing and Redefining Classes on the Fly 377 Objects Changing Their Class 380 Redefining CI asses 381 13-9. Making Your Objects Externalizable 383

试读 127P Common Lisp Recipes
立即下载 低至0.43元/次 身份认证VIP会员低至7折
zmcssl lisp 的好资源不多呀
lockedkey 么得,好人,感谢分享!
Common Lisp Recipes 10积分/C币 立即下载
Common Lisp Recipes第1页
Common Lisp Recipes第2页
Common Lisp Recipes第3页
Common Lisp Recipes第4页
Common Lisp Recipes第5页
Common Lisp Recipes第6页
Common Lisp Recipes第7页
Common Lisp Recipes第8页
Common Lisp Recipes第9页
Common Lisp Recipes第10页
Common Lisp Recipes第11页
Common Lisp Recipes第12页
Common Lisp Recipes第13页
Common Lisp Recipes第14页
Common Lisp Recipes第15页
Common Lisp Recipes第16页
Common Lisp Recipes第17页
Common Lisp Recipes第18页
Common Lisp Recipes第19页
Common Lisp Recipes第20页

试读结束, 可继续阅读

10积分/C币 立即下载 >