Etudes for Erlang

Etudes for Erlang

Simon St. Laurent

Language: English

Pages: 128

ISBN: 2:00151682

Format: PDF / Kindle (mobi) / ePub

Etudes for Erlang

Simon St. Laurent

Language: English

Pages: 128

ISBN: 2:00151682

Format: PDF / Kindle (mobi) / ePub


This is a companion book to Introducing Erlang

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

Debugging with Fiddler: The complete reference from the creator of the Fiddler Web Debugger

Learn You a Haskell for Great Good!: A Beginner's Guide

The Algorithm Design Manual (2nd Edition)

Advanced Qt Programming: Creating Great Software with C++ and Qt 4

Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming

Redmine Plugin Extension and Development

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-spec(range([number()]) -> [number()]). range(NumberList) -> [minimum(NumberList), maximum(NumberList)]. Solution 6-5 Here is a suggested solution for Étude 6-5. non_fp.erl %% %% %% %% %% @author J D Eisenberg @doc Generate a random set of teeth, with a certain percentage expected to be bad. @copyright 2013 J D Eisenberg @version 0.1 -module(non_fp). -export([generate_teeth/2, test_teeth/0]). %% @doc Generate a list of lists, six numbers per tooth, giving random

2013 J D Eisenberg @version 0.1 -module(cards). -export([make_deck/0, shuffle/1]). 82 | Appendix A: Solutions to Études %% @doc generate a deck of cards make_deck() -> [{Value, Suit} || Value <- ["A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K"], Suit <- ["Clubs", "Diamonds", "Hearts", "Spades"]]. shuffle(List) -> shuffle(List, []). %% If the list is empty, return the accumulated value. shuffle([], Acc) -> Acc; %% %% %% %% %% %% %% %% %% Otherwise, find a random location in the list and

handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> inets:stop(), ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%% Internal functions Solution 11-1 | 101 %% %% %% %% Given a weather station weather 4-letter station code as the Request, return its basic information as a {key,value} list. If successful, add the name to the State, which will keep track of recently-accessed stations. get_weather(Request, State) -> URL =

user profile handle_call(get_chat_node, _From, State) -> {reply, State#state.chat_node, State}; handle_call(get_profile, _From, State) -> {reply, State#state.profile, State}; handle_call({profile, Key, Value}, _From, State) -> case lists:keymember(Key, 1, State#state.profile) of true -> NewProfile = lists:keyreplace(Key, 1, State#state.profile, {Key, Value}); false -> NewProfile = [{Key, Value} | State#state.profile] end, {reply, NewProfile, #state{chat_node = State#state.chat_node,

get different random numbers. Don’t worry about the unde fined; that’s just Erlang’s way of telling you that the random number generator wasn’t seeded before. 1> random:seed(now()). undefined 2> random:uniform(). 0.27846009966109264 If you want to generate a random integer between 1 and N, use uniform/1; thus ran dom:uniform(10) will generate a random integer from 1 to 10. Functions that use random numbers have side effects; unlike the sin or sqrt function, which always gives you the same

Download sample

Download