A5下载 - 努力做内容最丰富最安全的下载站!

A5站长下载站

当前位置:A5下载 > 书籍教程 > 程序语言 > VB教程 > Erlang程序设计
Erlang程序设计

Erlang程序设计

  • 软件大小:1.76 MB
  • 软件语言:简体中文
  • 更新时间:2010-11-02
  • 软件类型:国产软件 / VB教程
  • 运行环境:PDF
  • 软件授权:免费软件
  • 官方主页:http://
  • 软件等级 :
  • 软件厂商:zhangyi
立即高速安全下载
  • 介绍说明
  • 下载地址
  • 精品推荐
  • 相关软件
  • 网友评论

英文名称:Programming Erlang_ Software for a Concurrent World

Erlang不但是一种编程语言,而且它具有比编程语言更加贴近操作系统的一些特性:并发线程、作业调度、内存管理、分布式、网络化等。

Erlang特性:
● 并发性 - Erlang支持超大量级的并发线程,并且不需要操作系统具有并发机制。
● 分布式 - 一个分布式Erlang系统是多个Erlang节点组成的网络(通常每个处理器被作为一个节点)
● 健壮性 - Erlang具有多种基本的错误检测能力,它们能够用于构建容错系统。
● 软实时性- Erlang支持可编程的“软”实时系统,使用了递增式垃圾收集技术。
● 热代码升级-Erlang允许程序代码在运行系统中被修改。旧代码能被逐步淘汰而后被新代码替换。在此过渡期间,新旧代码是共存的。
●递增式代码装载-用户能够控制代码如何被装载的细节。
●外部接口-Erlang进程与外部世界之间的通讯使用和在Erlang进程之间相同的消息传送机制。

Erlang组件:
● Inets - HTTP 1.0服务器和FTP客户端。
● Mnesia - 使用Erlang的分布式实时数据库。
● Orber - CORBA v2.0对象请求代理(ORB)。
●SNMP – 可扩展的SNMP v1/v2代理和MIB编译器。

目录:
Contents
1 Begin 12
1.1 Road Map . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Begin Again . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . 17
2 Getting Started 18
2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.2 Installing Erlang . . . . . . . . . . . . . . . . . . . . . . 21
2.3 The Code in This Book . . . . . . . . . . . . . . . . . . . 23
2.4 Starting the Shell . . . . . . . . . . . . . . . . . . . . . . 24
2.5 Simple Integer Arithmetic . . . . . . . . . . . . . . . . . 25
2.6 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.7 Floating-Point Numbers . . . . . . . . . . . . . . . . . . 32
2.8 Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.9 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.10 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.11 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.12 Pattern Matching Again . . . . . . . . . . . . . . . . . . 41
3 Sequential Programming 43
3.1 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.2 Back to Shopping . . . . . . . . . . . . . . . . . . . . . . 49
3.3 Functions with the Same Name and Different Arity . . 52
3.4 Funs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.5 Simple List Processing . . . . . . . . . . . . . . . . . . . 58
3.6 List Comprehensions . . . . . . . . . . . . . . . . . . . . 61
3.7 Arithmetic Expressions . . . . . . . . . . . . . . . . . . 64
3.8 Guards . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.9 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.10 case and if Expressions . . . . . . . . . . . . . . . . . . 72
3.11 Building Lists in Natural Order . . . . . . . . . . . . . . 73
3.12 Accumulators . . . . . . . . . . . . . . . . . . . . . . . . 74
CONTENTS 6
4 Exceptions 76
4.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.2 Raising an Exception . . . . . . . . . . . . . . . . . . . . 77
4.3 try...catch . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.4 catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.5 Improving Error Messages . . . . . . . . . . . . . . . . . 82
4.6 Programming Style with try...catch . . . . . . . . . . . . 82
4.7 Catching Every Possible Exception . . . . . . . . . . . . 83
4.8 Old- and New-Style Exception Handling . . . . . . . . . 84
4.9 Stack Traces . . . . . . . . . . . . . . . . . . . . . . . . . 84
5 Advanced Sequential Programming 86
5.1 BIFs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.2 Binaries . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.3 The Bit Syntax . . . . . . . . . . . . . . . . . . . . . . . 89
5.4 Miscellaneous Short Topics . . . . . . . . . . . . . . . . 98
6 Compiling and Running Your Program 118
6.1 Starting and Stopping the Erlang Shell . . . . . . . . . 118
6.2 Modifying the Development Environment . . . . . . . . 119
6.3 Different Ways to Run Your Program . . . . . . . . . . . 122
6.4 Automating Compilation with Makefiles . . . . . . . . . 127
6.5 Command Editing in the Erlang Shell . . . . . . . . . . 130
6.6 Getting Out of Trouble . . . . . . . . . . . . . . . . . . . 131
6.7 When Things Go Wrong . . . . . . . . . . . . . . . . . . 131
6.8 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . 134
6.9 Tweaking the Environment . . . . . . . . . . . . . . . . 135
6.10 The Crash Dump . . . . . . . . . . . . . . . . . . . . . . 136
7 Concurrency 137
8 Concurrent Programming 141
8.1 The Concurrency Primitives . . . . . . . . . . . . . . . . 142
8.2 A Simple Example . . . . . . . . . . . . . . . . . . . . . 143
8.3 Client-Server—An Introduction . . . . . . . . . . . . . . 144
8.4 How Long Does It Take to Create a Process? . . . . . . 148
8.5 Receive with a Timeout . . . . . . . . . . . . . . . . . . 150
8.6 Selective Receive . . . . . . . . . . . . . . . . . . . . . . 153
8.7 Registered Processes . . . . . . . . . . . . . . . . . . . . 154
8.8 How Do We Write a Concurrent Program? . . . . . . . . 156
8.9 A Word About Tail Recursion . . . . . . . . . . . . . . . 156
8.10 Spawning with MFAs . . . . . . . . . . . . . . . . . . . . 157
8.11 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
CONTENTS 7
9 Errors in Concurrent Programs 159
9.1 Linking Processes . . . . . . . . . . . . . . . . . . . . . . 159
9.2 An on_exit Handler . . . . . . . . . . . . . . . . . . . . . 160
9.3 Remote Handling of Errors . . . . . . . . . . . . . . . . 162
9.4 The Details of Error Handling . . . . . . . . . . . . . . . 162
9.5 Error Handling Primitives . . . . . . . . . . . . . . . . . 170
9.6 Sets of Linked Processes . . . . . . . . . . . . . . . . . . 172
9.7 Monitors . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
9.8 A Keep-Alive Process . . . . . . . . . . . . . . . . . . . . 173
10 Distributed Programming 175
10.1 The Name Server . . . . . . . . . . . . . . . . . . . . . . 177
10.2 The Distribution Primitives . . . . . . . . . . . . . . . . 182
10.3 Libraries for Distributed Programming . . . . . . . . . 185
10.4 The Cookie Protection System . . . . . . . . . . . . . . . 186
10.5 Socket-Based Distribution . . . . . . . . . . . . . . . . . 187
11 IRC Lite 191
11.1 Message Sequence Diagrams . . . . . . . . . . . . . . . 193
11.2 The User Interface . . . . . . . . . . . . . . . . . . . . . 194
11.3 Client-Side Software . . . . . . . . . . . . . . . . . . . . 195
11.4 Server-Side Software . . . . . . . . . . . . . . . . . . . . 199
11.5 Running the Application . . . . . . . . . . . . . . . . . . 203
11.6 The Chat Program Source Code . . . . . . . . . . . . . . 204
11.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
12 Interfacing Techniques 212
12.1 Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
12.2 Interfacing an External C Program . . . . . . . . . . . . 214
12.3 open_port . . . . . . . . . . . . . . . . . . . . . . . . . . 220
12.4 Linked-in Drivers . . . . . . . . . . . . . . . . . . . . . . 221
12.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
13 Programming with Files 226
13.1 Organization of the Libraries . . . . . . . . . . . . . . . 226
13.2 The Different Ways of Reading a File . . . . . . . . . . . 227
13.3 The Different Ways of Writing to a File . . . . . . . . . . 235
13.4 Directory Operations . . . . . . . . . . . . . . . . . . . . 239
13.5 Finding Information About a File . . . . . . . . . . . . . 240
13.6 Copying and Deleting Files . . . . . . . . . . . . . . . . 241
13.7 Bits and Pieces . . . . . . . . . . . . . . . . . . . . . . . 241
13.8 A Find Utility . . . . . . . . . . . . . . . . . . . . . . . . 242
CONTENTS 8
14 Programming with Sockets 245
14.1 Using TCP . . . . . . . . . . . . . . . . . . . . . . . . . . 246
14.2 Control Issues . . . . . . . . . . . . . . . . . . . . . . . . 255
14.3 Where Did That Connection Come From? . . . . . . . . 258
14.4 Error Handling with Sockets . . . . . . . . . . . . . . . 259
14.5 UDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
14.6 Broadcasting to Multiple Machines . . . . . . . . . . . 263
14.7 A SHOUTcast Server . . . . . . . . . . . . . . . . . . . . 265
14.8 Digging Deeper . . . . . . . . . . . . . . . . . . . . . . . 272
15 ETS and DETS: Large Data Storage Mechanisms 273
15.1 Basic Operations on Tables . . . . . . . . . . . . . . . . 274
15.2 Types of Table . . . . . . . . . . . . . . . . . . . . . . . . 275
15.3 ETS Table Efficiency Considerations . . . . . . . . . . . 276
15.4 Creating an ETS Table . . . . . . . . . . . . . . . . . . . 277
15.5 Example Programs with ETS . . . . . . . . . . . . . . . 279
15.6 DETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
15.7 What Haven’t We Talked About? . . . . . . . . . . . . . 287
15.8 Code Listings . . . . . . . . . . . . . . . . . . . . . . . . 288
16 OTP Introduction 291
16.1 The Road to the Generic Server . . . . . . . . . . . . . . 292
16.2 Getting Started with gen_server . . . . . . . . . . . . . 301
16.3 The gen_server Callback Structure . . . . . . . . . . . . 305
16.4 Code and Templates . . . . . . . . . . . . . . . . . . . . 309
16.5 Digging Deeper . . . . . . . . . . . . . . . . . . . . . . . 312
17 Mnesia: The Erlang Database 313
17.1 Database Queries . . . . . . . . . . . . . . . . . . . . . . 313
17.2 Adding and Removing Data in the Database . . . . . . 317
17.3 Mnesia Transactions . . . . . . . . . . . . . . . . . . . . 319
17.4 Storing Complex Data in Tables . . . . . . . . . . . . . 323
17.5 Table Types and Location . . . . . . . . . . . . . . . . . 325
17.6 Creating the Initial Database . . . . . . . . . . . . . . . 328
17.7 The Table Viewer . . . . . . . . . . . . . . . . . . . . . . 329
17.8 Digging Deeper . . . . . . . . . . . . . . . . . . . . . . . 329
17.9 Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
CONTENTS 9
18 Making a System with OTP 335
18.1 Generic Event Handling . . . . . . . . . . . . . . . . . . 336
18.2 The Error Logger . . . . . . . . . . . . . . . . . . . . . . 339
18.3 Alarm Management . . . . . . . . . . . . . . . . . . . . . 346
18.4 The Application Servers . . . . . . . . . . . . . . . . . . 348
18.5 The Supervision Tree . . . . . . . . . . . . . . . . . . . . 351
18.6 Starting the System . . . . . . . . . . . . . . . . . . . . 354
18.7 The Application . . . . . . . . . . . . . . . . . . . . . . . 358
18.8 File System Organization . . . . . . . . . . . . . . . . . 360
18.9 The Application Monitor . . . . . . . . . . . . . . . . . . 361
18.10 Digging Deeper . . . . . . . . . . . . . . . . . . . . . . . 361
18.11 How Did We Make That Prime? . . . . . . . . . . . . . . 363
19 Multicore Prelude 365
20 Programming Multicore CPUs 367
20.1 How to Make Programs Run Efficiently on a Multicore CPU368
20.2 Parallelizing Sequential Code . . . . . . . . . . . . . . . 372
20.3 Small Messages, Big Computations . . . . . . . . . . . 375
20.4 mapreduce and Indexing Our Disk . . . . . . . . . . . . 379
20.5 Growing Into the Future . . . . . . . . . . . . . . . . . . 389
A Documenting Our Program 390
A.1 Erlang Type Notation . . . . . . . . . . . . . . . . . . . . 391
A.2 Tools That Use Types . . . . . . . . . . . . . . . . . . . . 394
B Erlang on Microsoft Windows 396
B.1 Erlang . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
B.2 Fetch and Install MinGW . . . . . . . . . . . . . . . . . 396
B.3 Fetch and Install MSYS . . . . . . . . . . . . . . . . . . 397
B.4 Install the MSYS Developer Toolkit (Optional) . . . . . 397
B.5 Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
C Resources 399
C.1 Online Documentation . . . . . . . . . . . . . . . . . . . 399
C.2 Books and Theses . . . . . . . . . . . . . . . . . . . . . 400
C.3 Link Collections . . . . . . . . . . . . . . . . . . . . . . . 400
C.4 Blogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
C.5 Forums, Online Communities, and Social Sites . . . . 401
C.6 Conferences . . . . . . . . . . . . . . . . . . . . . . . . . 401
C.7 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
C.8 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . 402
CONTENTS 10
D A Socket Application 403
D.1 An Example . . . . . . . . . . . . . . . . . . . . . . . . . 403
D.2 How lib_chan Works . . . . . . . . . . . . . . . . . . . . 406
D.3 The lib_chan Code . . . . . . . . . . . . . . . . . . . . . 409
E Miscellaneous 419
E.1 Analysis and Profiling Tools . . . . . . . . . . . . . . . . 419
E.2 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 422
E.3 Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
E.4 Dynamic Code Loading . . . . . . . . . . . . . . . . . . . 435
F Module and Function Reference 439
F.1 Module: application . . . . . . . . . . . . . . . . . . . . . 439
F.2 Module: base64 . . . . . . . . . . . . . . . . . . . . . . . 440
F.3 Module: beam_lib . . . . . . . . . . . . . . . . . . . . . . 441
F.4 Module: c . . . . . . . . . . . . . . . . . . . . . . . . . . 441
F.5 Module: calendar . . . . . . . . . . . . . . . . . . . . . . 443
F.6 Module: code . . . . . . . . . . . . . . . . . . . . . . . . 444
F.7 Module: dets . . . . . . . . . . . . . . . . . . . . . . . . . 445
F.8 Module: dict . . . . . . . . . . . . . . . . . . . . . . . . . 448
F.9 Module: digraph . . . . . . . . . . . . . . . . . . . . . . . 449
F.10 Module: digraph_utils . . . . . . . . . . . . . . . . . . . 450
F.11 Module: disk_log . . . . . . . . . . . . . . . . . . . . . . 451
F.12 Module: epp . . . . . . . . . . . . . . . . . . . . . . . . . 452
F.13 Module: erl_eval . . . . . . . . . . . . . . . . . . . . . . . 453
F.14 Module: erl_parse . . . . . . . . . . . . . . . . . . . . . . 453
F.15 Module: erl_pp . . . . . . . . . . . . . . . . . . . . . . . 454
F.16 Module: erl_scan . . . . . . . . . . . . . . . . . . . . . . 454
F.17 Module: erl_tar . . . . . . . . . . . . . . . . . . . . . . . 454
F.18 Module: erlang . . . . . . . . . . . . . . . . . . . . . . . 455
F.19 Module: error_handler . . . . . . . . . . . . . . . . . . . 464
F.20 Module: error_logger . . . . . . . . . . . . . . . . . . . . 464
F.21 Module: ets . . . . . . . . . . . . . . . . . . . . . . . . . 465
F.22 Module: file . . . . . . . . . . . . . . . . . . . . . . . . . 468
F.23 Module: file_sorter . . . . . . . . . . . . . . . . . . . . . 470
F.24 Module: filelib . . . . . . . . . . . . . . . . . . . . . . . . 471
F.25 Module: filename . . . . . . . . . . . . . . . . . . . . . . 471
F.26 Module: gb_sets . . . . . . . . . . . . . . . . . . . . . . . 472
F.27 Module: gb_trees . . . . . . . . . . . . . . . . . . . . . . 474
F.28 Module: gen_event . . . . . . . . . . . . . . . . . . . . . 475
F.29 Module: gen_fsm . . . . . . . . . . . . . . . . . . . . . . 476
CONTENTS 11
F.30 Module: gen_sctp . . . . . . . . . . . . . . . . . . . . . . 477
F.31 Module: gen_server . . . . . . . . . . . . . . . . . . . . . 478
F.32 Module: gen_tcp . . . . . . . . . . . . . . . . . . . . . . . 478
F.33 Module: gen_udp . . . . . . . . . . . . . . . . . . . . . . 479
F.34 Module: global . . . . . . . . . . . . . . . . . . . . . . . . 479
F.35 Module: inet . . . . . . . . . . . . . . . . . . . . . . . . . 480
F.36 Module: init . . . . . . . . . . . . . . . . . . . . . . . . . 481
F.37 Module: io . . . . . . . . . . . . . . . . . . . . . . . . . . 481
F.38 Module: io_lib . . . . . . . . . . . . . . . . . . . . . . . . 482
F.39 Module: lib . . . . . . . . . . . . . . . . . . . . . . . . . . 483
F.40 Module: lists . . . . . . . . . . . . . . . . . . . . . . . . . 483
F.41 Module: math . . . . . . . . . . . . . . . . . . . . . . . . 487
F.42 Module: ms_transform . . . . . . . . . . . . . . . . . . . 487
F.43 Module: net_adm . . . . . . . . . . . . . . . . . . . . . . 487
F.44 Module: net_kernel . . . . . . . . . . . . . . . . . . . . . 488
F.45 Module: os . . . . . . . . . . . . . . . . . . . . . . . . . . 488
F.46 Module: proc_lib . . . . . . . . . . . . . . . . . . . . . . 489
F.47 Module: qlc . . . . . . . . . . . . . . . . . . . . . . . . . 489
F.48 Module: queue . . . . . . . . . . . . . . . . . . . . . . . 490
F.49 Module: random . . . . . . . . . . . . . . . . . . . . . . 491
F.50 Module: regexp . . . . . . . . . . . . . . . . . . . . . . . 492
F.51 Module: rpc . . . . . . . . . . . . . . . . . . . . . . . . . 492
F.52 Module: seq_trace . . . . . . . . . . . . . . . . . . . . . . 494
F.53 Module: sets . . . . . . . . . . . . . . . . . . . . . . . . . 494
F.54 Module: shell . . . . . . . . . . . . . . . . . . . . . . . . 495
F.55 Module: slave . . . . . . . . . . . . . . . . . . . . . . . . 495
F.56 Module: sofs . . . . . . . . . . . . . . . . . . . . . . . . . 496
F.57 Module: string . . . . . . . . . . . . . . . . . . . . . . . . 500
F.58 Module: supervisor . . . . . . . . . . . . . . . . . . . . . 501
F.59 Module: sys . . . . . . . . . . . . . . . . . . . . . . . . . 501
F.60 Module: timer . . . . . . . . . . . . . . . . . . . . . . . . 502
F.61 Module: win32reg . . . . . . . . . . . . . . . . . . . . . . 503
F.62 Module: zip . . . . . . . . . . . . . . . . . . . . . . . . . 504
F.63 Module: zlib . . . . . . . . . . . . . . . . . . . . . . . . . 504
Index 507

下载地址

  • PC版

本地下载

相关软件

查看所有评论+

网友评论

网友
您的评论需要经过审核才能显示

本类排名

本类推荐

装机必备

换一批

相关资讯

公众号