Erlang编程(影印版)
Erlang编程(影印版)
Francesco Cesarini, Simon Thompson
出版时间:2010年09月
页数:470
本书深入介绍了Erlang,这是一门满足高并发、容错和快速响应等苛刻要求的理想编程语言。随着多核CPU以及与之俱来的新并发扩展方式崭露头角,Erlang正在获得更广泛的接受和应用。只要拥有这本指南,无论此前的编程水平或经验如何,你都将学会用Erlang编写复杂的并发程序。

《Erlang编程》由Erlang国际社区的两位领袖级人物基于他们的培训教材撰写,重点解析该语言的语法和语义,并详细阐述模式匹配、严格列表(proper lists)、递归、调试、网络与并发等重要概念的精髓要义。

本书可以帮助你:
· 理解并掌握Erlang的诸多强项,以及其设计者潜心设计的各种特性
· 学习并发背后的概念和Erlang相应的处理方法
· 编写高效的Erlang程序,并且保持代码整洁易读
· 发现Erlang如何满足分布式系统的需求
· 小试牛刀,添加简单图形用户界面
· 学习Erlang的追踪机制,用于调试并发和分布式系统
· 使用内嵌的Mnesia数据库和其他表存储特性

无论你是新手还是富有经验的 Erlang开发者,《Erlang编程》都是案头必备的重要参考资料。

“尽管我已经使用Erlang多年,但在审读这份手稿的过程中,我还是常常在屏幕上打开该书某些章节,以便编程时引用。不同水平层次的所有Erlang程序员都能在这本颇具价值的好书中找到问题解答和参考材料。”
——Steve Vinoski,“The Functional Web”
专栏作家,《IEEE Internet Computing》杂志

Francesco Cesarini从事 Erlang/OTP 教学14年,学生不仅来自高校,还有开发者、测试人员和项目/技术经理。他帮助筹建了爱尔兰、美国和英国的 Erlang 开发中心。
Simon Thompson是一位来自肯特大学计算实验室的逻辑学与计算方法教授,在过去的25年中,他一直致力于本科生和研究生的计算机教学工作。
  1. Foreword
  2. Preface
  3. 1. Introduction
  4. Why Should I Use Erlang?
  5. The History of Erlang
  6. Erlang’s Characteristics
  7. High-Level Constructs
  8. Concurrent Processes and Message Passing
  9. Scalable, Safe, and Efficient Concurrency
  10. Soft Real-Time Properties
  11. Robustness
  12. Distributed Computation
  13. Integration and Openness
  14. Erlang and Multicore
  15. Case Studies
  16. The AXD301 ATM Switch
  17. CouchDB
  18. Comparing Erlang to C++
  19. How Should I Use Erlang?
  20. 2. Basic Erlang
  21. Integers
  22. The Erlang Shell
  23. Floats
  24. Mathematical Operators
  25. Atoms
  26. Booleans
  27. Tuples
  28. Lists
  29. Characters and Strings
  30. Atoms and Strings
  31. Building and Processing Lists
  32. List Functions and Operations
  33. Term Comparison
  34. Variables
  35. Complex Data Structures
  36. Pattern Matching
  37. Functions
  38. Modules
  39. Compilation and the Erlang Virtual Machine
  40. Module Directives
  41. Exercises
  42. 3. Sequential Erlang
  43. Conditional Evaluations
  44. The case Construct
  45. Variable Scope
  46. The if Construct
  47. Guards
  48. Built-in Functions
  49. Object Access and Examination
  50. Type Conversion
  51. Process Dictionary
  52. Meta Programming
  53. Process, Port, Distribution, and System Information
  54. Input and Output
  55. Recursion
  56. Tail-Recursive Functions
  57. Tail-Call Recursion Optimization
  58. Iterations Versus Recursive Functions
  59. Runtime Errors
  60. Handling Errors
  61. Using try ... catch
  62. Using catch
  63. Library Modules
  64. Documentation
  65. Useful Modules
  66. The Debugger
  67. Exercises
  68. 4. Concurrent Programming
  69. Creating Processes
  70. Message Passing
  71. Receiving Messages
  72. Selective and Nonselective Receives
  73. An Echo Example
  74. Registered Processes
  75. Timeouts
  76. Benchmarking
  77. Process Skeletons
  78. Tail Recursion and Memory Leaks
  79. A Case Study on Concurrency-Oriented Programming
  80. Race Conditions, Deadlocks, and Process Starvation
  81. The Process Manager
  82. Exercises
  83. 5. Process Design Patterns
  84. Client/Server Models
  85. A Client/Server Example
  86. A Process Pattern Example
  87. Finite State Machines
  88. An FSM Example
  89. A Mutex Semaphore
  90. Event Managers and Handlers
  91. A Generic Event Manager Example
  92. Event Handlers
  93. Exercises
  94. 6. Process Error Handling
  95. Process Links and Exit Signals
  96. Trapping Exits
  97. The monitor BIFs
  98. The exit BIFs
  99. BIFs and Terminology
  100. Propagation Semantics
  101. Robust Systems
  102. Monitoring Clients
  103. A Supervisor Example
  104. Exercises
  105. 7. Records and Macros
  106. Records
  107. Introducing Records
  108. Working with Records
  109. Functions and Pattern Matching over Records
  110. Records in the Shell
  111. Record Implementation
  112. Record BIFs
  113. Macros
  114. Simple Macros
  115. Parameterized Macros
  116. Debugging and Macros
  117. Include Files
  118. Exercises
  119. 8. Software Upgrade
  120. Upgrading Modules
  121. Behind the Scenes
  122. Loading Code
  123. The Code Server
  124. Purging Modules
  125. Upgrading Processes
  126. The .erlang File
  127. Exercise
  128. 9. More Data Types and High-Level Constructs
  129. Functional Programming for Real
  130. Funs and Higher-Order Functions
  131. Functions As Arguments
  132. Writing Down Functions: fun Expressions
  133. Functions As Results
  134. Using Already Defined Functions
  135. Functions and Variables
  136. Predefined, Higher-Order Functions
  137. Lazy Evaluation and Lists
  138. List Comprehensions
  139. A First Example
  140. General List Comprehensions
  141. Multiple Generators
  142. Standard Functions
  143. Binaries and Serialization
  144. Binaries
  145. The Bit Syntax
  146. Pattern-Matching Bits
  147. Bitstring Comprehensions
  148. Bit Syntax Example: Decoding TCP Segments
  149. Bitwise Operators
  150. Serialization
  151. References
  152. Exercises
  153. 10. ETS and Dets Tables
  154. ETS Tables
  155. Implementations and Trade-offs
  156. Creating Tables
  157. Handling Table Elements
  158. Example: Building an Index, Act I
  159. Traversing Tables
  160. Example: Building an Index, Act II
  161. Extracting Table Information: match
  162. Extracting Table Information: select
  163. Other Operations on Tables
  164. Records and ETS Tables
  165. Visualizing Tables
  166. Dets Tables
  167. A Mobile Subscriber Database Example
  168. The Database Backend Operations
  169. The Database Server
  170. Exercises
  171. 11. Distributed Programming in Erlang
  172. Distributed Systems in Erlang
  173. Distributed Computing in Erlang: The Basics
  174. Node Names and Visibility
  175. Communication and Security
  176. Communication and Messages
  177. Node Connections
  178. Remote Procedure Calls
  179. The rpc Module
  180. Essential Distributed Programming Modules
  181. The epmd Process
  182. Distributed Erlang Behind Firewalls
  183. Exercises
  184. 12. OTP Behaviors
  185. Introduction to OTP Behaviors
  186. Generic Servers
  187. Starting Your Server
  188. Passing Messages
  189. Stopping the Server
  190. The Example in Full
  191. Running gen_server
  192. Supervisors
  193. Supervisor Specifications
  194. Child Specifications
  195. Supervisor Example
  196. Dynamic Children
  197. Applications
  198. Directory Structure
  199. The Application Resource File
  200. Starting and Stopping Applications
  201. The Application Monitor
  202. Release Handling
  203. Other Behaviors and Further Reading
  204. Exercises
  205. 13. Introducing Mnesia
  206. When to Use Mnesia
  207. Configuring Mnesia
  208. Setting Up the Schema
  209. Starting Mnesia
  210. Mnesia Tables
  211. Transactions
  212. Writing
  213. Reading and Deleting
  214. Indexing
  215. Dirty Operations
  216. Partitioned Networks
  217. Further Reading
  218. Exercises
  219. 14. GUI Programming with wxErlang
  220. wxWidgets
  221. wxErlang: An Erlang Binding for wxWidgets
  222. Objects and Types
  223. Event Handling, Object Identifiers, and Event Types
  224. Putting It All Together
  225. A First Example: MicroBlog
  226. The MiniBlog Example
  227. Obtaining and Running wxErlang
  228. Exercises
  229. 15. Socket Programming
  230. User Datagram Protocol
  231. Transmission Control Protocol
  232. A TCP Example
  233. The inet Module
  234. Further Reading
  235. Exercises
  236. 16. Interfacing Erlang with Other Programming Languages
  237. An Overview of Interworking
  238. Interworking with Java
  239. Nodes and Mailboxes
  240. Representing Erlang Types
  241. Communication
  242. Putting It Together: RPC Revisited
  243. Interaction
  244. The Small Print
  245. Taking It Further
  246. C Nodes
  247. Going Further
  248. Erlang from the Unix Shell: erl_call
  249. Port Programs
  250. Erlang Port Commands
  251. Communicating Data to and from a Port
  252. Library Support for Communication
  253. Working in Ruby: erlectricity
  254. Linked-in Drivers and the FFI
  255. Exercises
  256. 17. Trace BIFs, the dbg Tracer, and Match Specifications
  257. Introduction
  258. The Trace BIFs
  259. Process Trace Flags
  260. Inheritance Flags
  261. Garbage Collection and Timestamps
  262. Tracing Calls with the trace_pattern BIF
  263. The dbg Tracer
  264. Getting Started with dbg
  265. Tracing and Profiling Functions
  266. Tracing Local and Global Function Calls
  267. Distributed Environments
  268. Redirecting the Output
  269. Match Specifications: The fun Syntax
  270. Generating Specifications Using fun2ms
  271. Difference Between ets and dbg Match Specifications
  272. Match Specifications: The Nuts and Bolts
  273. The Head
  274. Conditions
  275. The Specification Body
  276. Saving Match Specifications
  277. Further Reading
  278. Exercises
  279. 18. Types and Documentation
  280. Types in Erlang
  281. An Example: Records with Typed Fields
  282. Erlang Type Notation
  283. TypEr: Success Types and Type Inference
  284. Dialyzer: A DIscrepancy AnaLYZer for ERlang Programs
  285. Documentation with EDoc
  286. Documenting usr_db.erl
  287. Running EDoc
  288. Types in EDoc
  289. Going Further with EDoc
  290. Exercises
  291. 19. EUnit and Test-Driven Development
  292. Test-Driven Development
  293. EUnit
  294. How to Use EUnit
  295. Functional Testing, an Example: Tree Serialization
  296. The EUnit Infrastructure
  297. Assert Macros
  298. Test-Generating Functions
  299. EUnit Test Representation
  300. Testing State-Based Systems
  301. Fixtures: Setup and Cleanup
  302. Testing Concurrent Programs in Erlang
  303. Exercises
  304. 20. Style and Efficiency
  305. Applications and Modules
  306. Libraries
  307. Dirty Code
  308. Interfaces
  309. Return Values
  310. Internal Data Structures
  311. Processes and Concurrency
  312. Stylistic Conventions
  313. Coding Strategies
  314. Efficiency
  315. Sequential Programming
  316. Lists
  317. Tail Recursion and Non-tail Recursion
  318. Concurrency
  319. And Finally...
  320. Appendix: Using Erlang
  321. Index
书名:Erlang编程(影印版)
国内出版社:东南大学出版社
出版时间:2010年09月
页数:470
书号:978-7-5641-2269-0
原版书出版商:O'Reilly Media
Francesco Cesarini
 
Francesco Cesarini是Erlang语言培训和咨询公司创始人(http://www.erlang-consulting.com)。从1995年开始,他差不多每天都在使用Erlang语言, 而他第一次接触Erlang是当他在Erlang的诞生地 —— 爱立信计算机科学实验室组实习的时候。他在爱立信参与了Erlang的旗舰项目并持续了4年,其中包括了OTP 中间件R1的发布版本。他热衷于对参与软件开发周期各个环节的各方人员包括开发工程师、支持工程师、测试人员、项目经理和技术经理传授关于Erlang/OTP方面的相关知识。2003年,他开始在哥德堡大学的计算机系教授本科生。
在Erlang开源发布不久,他就成立了Erlang培训和咨询公司。公司在英国、瑞典和波兰(很快在美国)都设有办事处,并已成为有关Erlang咨询、承包合同、支持、培训和系统开发方面的世界领先者。Francesco在Erlang社区非常活跃,他不仅仅出现在Erlang的各种定期讲座、研讨会和多次在全球会议上演讲,而且还参与国际性的一些研究项目。他组织Erlang的地方用户组,并在同事的帮助下,运行维护trapexit.org这个 Erlang社区网站。
 
 
Simon Thompson
 
Simon Thompson是一位在肯特大学计算实验室工作的逻辑和计算学教授,他教授本科生和研究生的计算学课程已经有25年了,而且6年前他成为了计算机系的部门负责人。他的研究工作主要集中在函数式编程:程序验证、类型系统以及最近关于函数编程语言方面的软件开发工具的开发。他的团队已经开发出了关于Haskell语言的重构工具HaRe,现在他们正在开发类似的关于Erlang语言的重构工具Wrangler。
很多机构(包括自然科学基金委员会和欧洲框架计划组织)都资助Simon的研究工作。他拥有剑桥大学的数学硕士学位和牛津大学的数理逻辑博士学位。他在感兴趣的领域著有3本书:《Type Theory and Functional Programming》、《Miranda: The Craft of Functional Programming》和《Haskell: The Craft of Functional Programming》(Second Edition),这3本书已由Addison - Wesley出版社出版。
 
 
The animal on the cover of Erlang Programming is a brush-tailed rat kangaroo
(Bettongia penicillata). The brush-tailed rat kangaroo is a small mammal found in
western and southern Australia. It is a cross between a rat and a small wallaby, and
although some of its features are reminiscent of a rat, it is not a rodent and is instead
classified as a marsupial. In south Australia, they are found in semi-arid scrublands and
grasslands; in western Australia, they prefer eucalyptus forests containing a vegetative
layer of tussock grass, low woody scrub, and occasional bare patches of ground. They once inhabited more than 60% of the Australian mainland, but now they inhabit less
than 1%.
Brush-tailed rat kangaroos have an unusual mammalian diet that consists of bulbs,
tubers, seeds, insects, resins, and underground fungi; they do not drink water or eat
green plants. Although fungi are not considered a good food source for mammals in
general, they provide the nutrients necessary for the brush-tailed rat-kangaroo’s health.
The kangaroos’ coats are yellowish-gray in color, their feet are pale brown and have
hairs that bristle, and their long tails have a prominent black crest. Their tails are also
useful: brush-tailed rat kangaroos are able to curl their tails to carry bundles of material
to build their nests. They are relatively slow-moving creatures, but are able to hop away
quickly when disturbed.
Brush-tailed rat kangaroos are extremely nocturnal. During the day they rest in wellconstructed,
hidden nests made up of grass and shredded bark. They appear to be
solitary except when ready to mate.
Mating occurs year round, and females give birth to one young after a gestation period
of 21 days. The newborn remains in the mother’s pouch for about 98 days, and then
stays in a nest until a new infant is born. As with many other kangaroos, the brushtailed
rat kangaroo mates shortly after giving birth and can keep embryos in a state of
dormancy until they are needed.