Erlang Programming Learning

cjnick38404 72 0 PDF 2020-07-30 19:07:42

An overall learning material of Erlang Programing. Suitable for both newbie and experienced developer.Erlang Programmingfrancesco Cesarini and simon Thompson○ REILLYBeijing· Cambridge: Farnham·Kdln· Sebastopol· Taipei· TokyoErlang programmingby Francesco Cesarini and Simon ThompsonCopyright o 2009 Francesco Cesarini and Simon Thompson. All rights reservedPrinted in the United States of americaPublished by O Reilly Media, Inc, 1005 Gravenstein Highway North, Sebastopol, CA 95472O'Reilly books may be purchased for educational, business, or sales promotional use. Online editionsarealsoavailableformosttitles(http://my.safaribooksonline.com).Formoreinformationcontactourcorporate/institutionalsalesdepartment(800)998-9938orcorporate@oreilly.comEditor: Mike LoukidesIndexer: Lucie HaskinsProduction Editor: Sumita MukherjCover Designer: Karen montgomeryCopyeditor: Audrey doyleInterior Designer David FutatoProofreader: Sumita MukherjiIllustrator: Robert romanoPrinting History:June 2009First editionNutshell Handbook, the Nutshell Handbook logo, and the O' Reilly logo are registered trademarks ofO'Reilly Media, InC. Erlang Programming, the image of a brush-tailed rat kangaroo, and related tradedress are trademarks of O'Reilly Media, IncMany of the designations used by manufacturers and sellers to distinguish their products are claimed asrademarks. Where those designations appear in this book, and O Reilly Media, Inc was aware of atrademark claim, the designations have been printed in caps or initial capsWhile every precaution has been taken in the preparation of this book, the publisher and authors assumeno responsibility for errors or omissions, or for damages resulting from the use of the information con-tained hereinRepkoverThis book uses RepkoverTM, a durable and flexible lay-flat bindingISBN:978-0-596-51818-91244557300Table of contentsForewordPreface1. IntroductionWhy Should I Use erlang?The history of erlanggErlang's CharacteristicsHigh-Level ConstructsConcurrent Processes and Message passiScalable, Safe, and Efficient ConcurrencySoft Real-Time PropertiesRobustnessDistributed Computation113445666789Integration and opennessErlang and multicoreCase studiesThe aXD301 ATM Switch10CouchDBComparing erlang to C++12How Should I Use erlang?14Basic Erlang∴15IntegersThe erlang shell11FloatsMathematical OperatorsAtoms19Booleans2021ListsCharacters and Strings22Atoms and stringsBuilding and Processing ListsList Functions and Operationserm comparison28VariablesComplex Data Structures32Pattern MatchingFunctions38ModulesCompilation and the erlang Virtual machine40Module directives41Exercises3. Sequential Erlang∴Conditional evaluationsThe case construct46Vbarable scope48The if Construct49Guards50Built-in functionsObject Access and ExaminationType Conversion54Process DictionaryMeta ProgrammingProcess, Port, Distribution, and System Information56Input and Output7RecursionTail-Recursive Functions63Tail-Call Recursion Optimization66Iterations versus recursive functionsRuntime errorsHandling Errors70Using try… catch70Using catchLibrary modulesDocumentationUseful modules79The debiExercises824.〔 oncurrent Programming………,89Creating Processes90Message Passing2iv Table of ContentsReceiving Messages94Selective and nonselective receivesAn Echo Example100Registered Processes102Timeouts104Benchmarking106Process skeletons107Tail Recursion and Memory leaks108A Case Study on Concurrency-Oriented Programming110Race Conditions. Deadlocks. and Process starvation112The Process manager114Exercises1155. Process design Patterns.........................117Client/Server ModelsA Client/Server Exampl119A Process Pattern Example125Finite State machines126An FSM Examplple127A Mutex Semaphore129Event managers and handlers131A Generic Event Manager Exampl132Event handlers135Exercises1376. Process Error handling139Process Links and Exit signals139Trapping Exits142The monitor bifs144The exit bifs145BIFs and Terminology146Propagation Semantics148Robust Systems148Monitoring Clients150A Supervisor example152Exercises1547. Records and macros157158Introducing records158Working with Records159Functions and Pattern Matching over Records160Records in the shell161Table of Contents vRecord implementation162Record bifs164165Simple macros165Parameterized macros166bugging and macros166Include files168Exercises1688. Software Upgrade∴Upgradingovules173Behind the scenesLoading Code179The Code server180Purging modules182Upgrading Processes182The erlang fil186Exercise1869. More Data Types and High-Level ConsFunctional Programming for Real189Funs and Higher-Order Functions190Functions As arguments190Writing down Functions: fun Expressions192Functions As results193Using Already Defined Functions194Functions and variables195Predefined, Higher-Order Functions195Lazy Evaluation and Lists197List Comprehensions198A First Example198General List Comprehensions198Multiple generator200Standard functions200Binaries and serialization201Binaries202The Bit syntax203Pattern-Matching Bits205Bitstring Comprehensions206Bit Syntax Example: Decoding TCP Segments206Bitwise Operators208Serialization208210ⅵ i Table of ContentsExercises21110. ETS and dets tables鲁非213ETS Tables213Implementations and trade-offs214Creating Tables216Handling table elements217Example: Building an Index, Act I218Traversing tables220Example: Building an index, Act II222Extracting Table Information: match223xtracting Table Information: select225Other Operations on tables226Records and ets tables6VisualizingTables228Dets tables229A Mobile Subscriber database Example231The Database Backend Operations232The database server237Exercises24211. Distributed Programming in Erlang...........245Distributed Systems in Erlang245Distributed Computing in Erlang: The Basics247ode names and visibility249Communication and securit250Communication and messages252Node connections253Remote Procedure Calls256The rpc module258Essential Distributed Programming modules258The epmd Process260Distributed Erlang behind Firewalls261Exercises26112. oTP Behaviors263Introduction to otp behaviors263Generic servers266Starting Your Server266ing Messages268opping the servertopp270The Example in Full271Running gen_server273Table of contents|ⅶiSupervisors276Supervisor specifications277Child specifications278Supervisor Example279Dynamic Children280Applications281Directory Structure282The application resource File283Starting and Stopping applications284The application Monitor287Release handling287Other Behaviors and Further reading290Exercises29113. Introducing Mnesia293When to Use mnesia293Configuring Mnesia295tingUp the scheema295Starting mnesia296Mnesia tables296299ing299Reading and deleting300XIng301Dirty operations302Partitioned Networks304Further reading305Exercises30614. GUI Programming with wxErlang309wxWidgets309wxErlang: An Erlang Binding for wx Widgets310bjects and Types311Event Handling, Object Identifiers, and Event Types312Putting It All Together313A First Example: MicroBlog314The Miniblog example317Obtaining and running wxerlang321Exercises32115. Socket Programming,323User Datagram Protocol323Transmission Control protocol327ⅶ ii Table of Contents

Erlang Programming Learning

用户评论
请输入评论内容
评分:
暂无评论