Introducing Erlang

Introducing Erlang

Simon St. Laurent

Language: English

Pages: 201

ISBN: 1449331769

Format: PDF / Kindle (mobi) / ePub

Simon St. Laurent, "Introducing Erlang" English | ISBN: 1449331769 | 2013 | Publisher: O’Reilly Media | PDF | 202 pages | 7 + 3 MB

If you’re new to Erlang, its functional style can seem difficult, but with help from this hands-on introduction, you’ll scale the learning curve and discover how enjoyable, powerful, and fun this language can be.

Author Simon St. Laurent shows you how to write simple Erlang programs by teaching you one basic skill at a time. You’ll learn about pattern matching, recursion, message passing, process-oriented programming, and establishing pathways for data rather than telling it where to go. By the end of your journey, you’ll understand why Erlang is ideal for concurrency and resilience.
Get cozy with Erlang’s shell, its command line interface
Become familiar with Erlang’s basic structures by working with numbers
Discover atoms, pattern matching, and guards: the foundations of your program structure
Delve into the heart of Erlang processing with recursion, strings, lists, and higher-order functions
Create processes, send messages among them, and apply pattern matching to incoming messages
Store and manipulate structured data with Erlang Term Storage and the Mnesia database
Learn about Open Telecom Platform, Erlang’s open source libraries and tools

Windows Server 2012 Hyper-V Cookbook

One Billion Rising: Law, Land and the Alleviation of Global Poverty

Original Wisdom: Stories of an Ancient Way of Knowing

Jump Start Rails

Building Web Reputation Systems


















drop:fall_velocity(mars,-20). ** exception error: no case clause matching mars in function drop:fall_velocity/2 (drop.erl, line 6) The error is correct, in that the case construct is trying to match mars, but misleading because the problem isn’t with mars but rather with the guard that’s checking the Distance variable. If Erlang tells you that your case doesn’t match but a match is obviously right there in front of you, check your guard statements. If This, Then That The if construct

set—each key maps to only one instance of record, and ETS doesn’t keep the list sorted by key. Once you have the table set up, as shown in Example 10-5, you use the ets:info/1 function to check out its details. (You can find this in ch10/ex4-ets.) Example 10-5. Setting up a simple ETS table and reporting on what’s there -module(planemo_storage). -export([setup/0]). -include("records.hrl"). setup() -> PlanemoTable=ets:new(planemos, [named_table, {keypos,}]),

but it is good to see the name(planemos), size (0—empty!), and keypos (not 1, the default, but 2, the location of the name in the tuple underneath the record). It is, as the defaults specify, set up as a protected set. You can set up only one ETS table with the same name. If you call planemo_storage:setup/0 twice, you’ll get an error: 3> planemo_storage:setup(). ** exception error: bad argument in function ets:new/2 called as ets:new(planemos,[named_table,{keypos,2}]) in call from

?MODULE). %%% convenience method for startup start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). %%% supervisor callback init([]) -> RestartStrategy = one_for_one, MaxRestarts = 1, % one restart every MaxSecondsBetweenRestarts = 5, % five seconds SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, Restart = permanent, % or temporary, or transient Shutdown = 2000, % milliseconds, could be infinity or brutal_kill Type = worker, % could also be supervisor Drop =

ls(). drop.beam drop.erl ok Line 1 checks to see if the drop.erl source file is there, and you see the directory listing. Line 2 actually compiles it, and line 3 shows that a new file, drop.beam, is now available. Now that you have drop.beam, you can call functions from the module. You need to prefix those calls with drop, as shown in lines 4 and 5 of the following code. 4> drop:fall_velocity(20). 19.79898987322333 5> drop:mps_to_mph(drop:fall_velocity(20)). 44.289078952755766 It works the

Download sample