所需积分/C币:45 2018-04-03 20:21:22 5.08MB PDF
收藏 收藏

《erlang编程指南》是对erlang语言的深入介绍。erlang是任何必须并发、容错和快速响应的环境的理想编程语言。随着多核处理器及其针对并发的新的可扩展方式的发展,erlang得到了广泛的使用。通过本书,你将学会如何使用erlang编写复杂的并发程序,不管你是否有编程背景和经验。 本书由国际知名的erlang社区领导者根据他们的培训材料编写而成。本书的重点集中在解释erlang的语法和语义,并且介绍了其模式匹配、规范列表、递归、调试、网络和并发性等内容。
Erlang Programming francesco Cesarini and simon Thompson ○ REILLY Beijing· Cambridge: Farnham·Kdln· Sebastopol· Taipei· Tokyo Erlang programming by Francesco Cesarini and Simon Thompson Copyright o 2009 Francesco Cesarini and Simon Thompson. All rights reserved Printed in the United States of america Published by O Reilly Media, Inc, 1005 Gravenstein Highway North, Sebastopol, CA 95472 O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions arealsoavailableformosttitles( corporate/institutionalsalesdepartment(800) Editor: Mike Loukides Indexer: Lucie Haskins Production Editor: Sumita Mukherj Cover Designer: Karen montgomery Copyeditor: Audrey doyle Interior Designer David Futato Proofreader: Sumita Mukherji Illustrator: Robert romano Printing History: June 2009 First edition Nutshell Handbook, the Nutshell Handbook logo, and the O Reilly logo are registered trademarks of O'Reilly Media, InC. Erlang Programming, the image of a brush-tailed rat kangaroo, and related trade dress are trademarks of O'Reilly Media, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as rademarks. Where those designations appear in this book, and O Reilly Media, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein Repkover This book uses RepkoverTM, a durable and flexible lay-flat binding ISBN:978-0-596-51818-9 1244557300 Table of contents Foreword Preface 1. Introduction Why Should I Use erlang? The history of erlang g Erlang's Characteristics High-Level Constructs Concurrent Processes and Message passi Scalable, Safe, and Efficient Concurrency Soft Real-Time Properties Robustness Distributed Computation 113445666789 Integration and openness Erlang and multicore Case studies The aXD301 ATM Switch 10 CouchDB Comparing erlang to C++ 12 How Should I Use erlang? 14 Basic Erlang∴ 15 Integers The erlang shell 11 Floats Mathematical Operators Atoms 19 Booleans 20 21 Lists Characters and Strings 22 Atoms and strings Building and Processing Lists List Functions and Operations erm comparison 28 Variables Complex Data Structures 32 Pattern Matching Functions 38 Modules Compilation and the erlang Virtual machine 40 Module directives 41 Exercises 3. Sequential Erlang∴ Conditional evaluations The case construct 46 V b arable scope 48 The if Construct 49 Guards 50 Built-in functions Object Access and Examination Type Conversion 54 Process Dictionary Meta Programming Process, Port, Distribution, and System Information 56 Input and Output 7 Recursion Tail-Recursive Functions 63 Tail-Call Recursion Optimization 66 Iterations versus recursive functions Runtime errors Handling Errors 70 Using try… catch 70 Using catch Library modules Documentation Useful modules 79 The debi Exercises 82 4.〔 oncurrent Programming……… ,89 Creating Processes 90 Message Passing 2 iv Table of Contents Receiving Messages 94 Selective and nonselective receives An Echo Example 100 Registered Processes 102 Timeouts 104 Benchmarking 106 Process skeletons 107 Tail Recursion and Memory leaks 108 A Case Study on Concurrency-Oriented Programming 110 Race Conditions. Deadlocks. and Process starvation 112 The Process manager 114 Exercises 115 5. Process design Patterns.........................117 Client/Server Models A Client/Server Exampl 119 A Process Pattern Example 125 Finite State machines 126 An FSM Exampl ple 127 A Mutex Semaphore 129 Event managers and handlers 131 A Generic Event Manager Exampl 132 Event handlers 135 Exercises 137 6. Process Error handling 139 Process Links and Exit signals 139 Trapping Exits 142 The monitor bifs 144 The exit bifs 145 BIFs and Terminology 146 Propagation Semantics 148 Robust Systems 148 Monitoring Clients 150 A Supervisor example 152 Exercises 154 7. Records and macros 157 158 Introducing records 158 Working with Records 159 Functions and Pattern Matching over Records 160 Records in the shell 161 Table of Contents v Record implementation 162 Record bifs 164 165 Simple macros 165 Parameterized macros 166 bugging and macros 166 Include files 168 Exercises 168 8. Software Upgrade∴ Upgrading ovules 173 Behind the scenes Loading Code 179 The Code server 180 Purging modules 182 Upgrading Processes 182 The erlang fil 186 Exercise 186 9. More Data Types and High-Level Cons Functional Programming for Real 189 Funs and Higher-Order Functions 190 Functions As arguments 190 Writing down Functions: fun Expressions 192 Functions As results 193 Using Already Defined Functions 194 Functions and variables 195 Predefined, Higher-Order Functions 195 Lazy Evaluation and Lists 197 List Comprehensions 198 A First Example 198 General List Comprehensions 198 Multiple generator 200 Standard functions 200 Binaries and serialization 201 Binaries 202 The Bit syntax 203 Pattern-Matching Bits 205 Bitstring Comprehensions 206 Bit Syntax Example: Decoding TCP Segments 206 Bitwise Operators 208 Serialization 208 210 ⅵ i Table of Contents Exercises 211 10. ETS and dets tables 鲁非 213 ETS Tables 213 Implementations and trade-offs 214 Creating Tables 216 Handling table elements 217 Example: Building an Index, Act I 218 Traversing tables 220 Example: Building an index, Act II 222 Extracting Table Information: match 223 xtracting Table Information: select 225 Other Operations on tables 226 Records and ets tables 6 Visualizing Tables 228 Dets tables 229 A Mobile Subscriber database Example 231 The Database Backend Operations 232 The database server 237 Exercises 242 11. Distributed Programming in Erlang........... 245 Distributed Systems in Erlang 245 Distributed Computing in Erlang: The Basics 247 ode names and visibility 249 Communication and securit 250 Communication and messages 252 Node connections 253 Remote Procedure Calls 256 The rpc module 258 Essential Distributed Programming modules 258 The epmd Process 260 Distributed Erlang behind Firewalls 261 Exercises 261 12. oTP Behaviors 263 Introduction to otp behaviors 263 Generic servers 266 Starting Your Server 266 ing Messages 268 opping the server top p 270 The Example in Full 271 Running gen_server 273 Table of contents|ⅶi Supervisors 276 Supervisor specifications 277 Child specifications 278 Supervisor Example 279 Dynamic Children 280 Applications 281 Directory Structure 282 The application resource File 283 Starting and Stopping applications 284 The application Monitor 287 Release handling 287 Other Behaviors and Further reading 290 Exercises 291 13. Introducing Mnesia 293 When to Use mnesia 293 Configuring Mnesia 295 ting Up the sche ema 295 Starting mnesia 296 Mnesia tables 296 299 ing 299 Reading and deleting 300 XIng 301 Dirty operations 302 Partitioned Networks 304 Further reading 305 Exercises 306 14. GUI Programming with wxErlang 309 wxWidgets 309 wxErlang: An Erlang Binding for wx Widgets 310 bjects and Types 311 Event Handling, Object Identifiers, and Event Types 312 Putting It All Together 313 A First Example: MicroBlog 314 The Miniblog example 317 Obtaining and running wxerlang 321 Exercises 321 15. Socket Programming ,323 User Datagram Protocol 323 Transmission Control protocol 327 ⅶ ii Table of Contents

试读 127P Erlang编程指南
立即下载 低至0.43元/次 身份认证VIP会员低至7折
  • 分享达人

关注 私信 TA的资源
    Erlang编程指南 45积分/C币 立即下载

    试读结束, 可继续阅读

    45积分/C币 立即下载 >