Updates for 18.0! Many of them are minor (although incredibly useful) improvements, but there is one major change that is a bit complex that came with this new version: a new time API. The time API changes how we should handle time and gives us new very interesting mechanisms to deal with clocks drifting around through time. In this addition, I try to explain things to be as clear as possible so…
Oh hi. It's been a while. This is an add-on chapter, one that isn't yet part of the printed version of Learn You Some Erlang for great good! Why does this exist? Was the printed book a huge steaming pile of bad information? I hope not (though you can consult the errata to see how wrong it is). The reason for this chapter is that the Erlang zoo of data types has grown just a bit larger with the R17…
Hi everyone who still follows this RSS feed even though the text was marked as done. I'm creating an event there to announce that Learn You Some Erlang for Great Good! is now available as a book from No Starch Press (http://nostarch/erlang). Moreover, the text of the LYSE website has gone under a lot of small changes and fixes in the last few months, mostly typoes, little bugs in implementations,…
This is LYSE's final and last chapter. In this one, we learn how to use Dialyzer to type check our programs and get a few of static languages' advantages, but with a twist. Dialyzer uses success types, a type of inference that matches the realities of the language better.
Using Common Test and a TDD-like approach, we learn how to use Mnesia, a database written in Erlang, storing data within your VM. It supports full distribution with replication, storage both in RAM and on disk, and all types of queries that made ETS useful wrapped inside transactions. This knowledge is then put to use by writing a Godfather-themed application to track friends and foes across…
Common Test from the bottom up. Common Test is a test framework for system testing and unit testing in Erlang, allowing basic tests to distributed tests. This chapter shows the basic functionalities required to write, read, and understand how Common Test works.
A chapter on how to use the built-in distribution features of OTP applications, allowing for a takeover and failover mechanism to be added to your application.
An introduction to distributed computing in the context of Erlang. Material such as the fallacies of distributed computing and the CAP theorem are taught to the reader in a zombie survival set-up. Lastly, all the basic BIFs and options to connect Erlang VMs in a distributed setting are shown.
ETS is a memory-based database to store any kind of Erlang terms within the VM. We learn how to use it and then optimize our process registry to use it and be faster in general.
Because of practical necessities when codebases grow, this chapter shows how to to use EUnit, from its most basic uses to effectively testing some OTP code. This includes running tests, writing test generators, using fixtures, and testing a process registry server (OTP code!) to make sure it works fine.
Going through socket programming in Erlang. We see how to use TCP and UDP sockets with the gen_udp and gen_tcp modules. Topics seen include rate limiting, IO lists, controlling processes and supervisors for TCP/UDP. For a practical aspect of it, we go through the implemention of sockersv, the text-based TCP socket server for Process Quest that can be used to communicate with Telnet for the RPG…
Using a clone of Progress Quest written in Erlang, this chapter explains how to safely update the code while it's running, without dropping a single session. This makes use of some of our newly acquired knowledge of releases and some of the OTP material. This is one of the final steps to understanding OTP itself, and readers who internalize all the material seen so far should be able to consider…
This is one of the really obscure while incredibly useful sections of OTP: how to package OTP applications as releases. Making releases with OTP tools is somewhat a black art because the standard documentation is more of a reference than a tutorial. Hopefully this chapter will make light of OTP releases built with both Systools and Reltool. We'll be packaging our erlcount application and its…
We kill a two-month hiatus with two chapters on OTP applications. The first one (Building OTP Applications) aims to show the basic concepts behind OTP applications by packaging our process pool into the standard OTP structure. The second one (The Count of Applications) shows how to build something with more than one app, by using the ppool app to run regular expressions on a fixed number of files…
This chapter lets us make practical use of the OTP behaviours seen so far. We do this by writing a process pool application that will let us handle resources and tasks. We explore ideas behind process trees, onion layer theories for processes and general views of how OTP can be used to write software.
Right in time before the Bay Area Erlang Conference, the supervisors make their place in Learn You Some Erlang. We see how to set up an OTP supervisor, the restart strategies available, how to write children specifications and have a little demonstration where a band manager takes pleasure at firing band members.
Event handlers are one of the most underappreciated behaviours available in OTP (generally only used for alarms and loggers). In this chapter, we see them from a broader angle. We'll be seeing the principles behind event handlers, their generic OTP form with gen_event, and then how event managers and handlers can be used in the context of an Olympic curling game where we need to react to a bunch…
Rage Against The Finite-State Machines introduces the reader to the concept of finite-state machines and how they're generalised in the OTP framework. We get to write an asynchronous concurrent protocol for a trading system for items between two players for a fictive game. We then implement the protocol by using the gen_fsm behaviour in the OTP way.
Two new chapters, 'What is OTP?' and 'Clients and Servers'. In the first one, the basic ideas behind the OTP framework are explained through the abstraction of a basic client-server pattern into generic and specific components. The latter, the abstraction is pushed further by using the OTP gen_server behaviour to get things going.
In this chapter, we write a short concurrent application while reviwing Erlang concurrency primitives: processes, links, monitors, hot code loading and message passing. The process acts as a primer before OTP and a general overview of how to plan a concurrent application.
Errors and Processes might be the last chapter released before Learn You Some Erlang hits its one year mark (see: http://ferd.ca/learn-you-some-erlang-a-year-in.html). Thanks to all dedicated readers and reviewers. This chapter covers the building blocks of error management with concurrent Erlang: linking processes together, handling different signals sent between processes when they crash,…
This chapter's a bit of an extension on the practical aspects of the Hitchhiker's Guide to Concurrency. New multiprocessing and concurrent aspects of Erlang are seen, including how to hold state in processes, useful abstractions when passing messages, how to handle timeouts and then selective receives for prioritizing messages. I'm publishing this chapter in English on the night of our…
I was a bit slow to produce this chapter, but I'll blame that on my laptop dying on me and playoffs Hockey (watching a game as I'm writing this!) Anyway, this is the first chapter to really talk about Erlang's concurrency. Because of this, I'm taking a theoretical approach and visiting the language's history a little bit, explaining the rationale and doing a quick overview of how processes work in…
Chances are you now understand the functional subset of Erlang pretty well and could read many programs without a problem. However, I still feel like there's a few things missing. In this last chapter about the functional subset of Erlang, I cover concepts such as records, key-value stores, sets and other data structures that are part of the standard library.
A new chapter arrives. This one is about putting to practice what was seen in Learn You Some Erlang until now. The problems are borrowed from Learn You A Haskell and are about implementing a Reverse Polish Notation calculator with pattern matching and finding the shortest path from Heathrow to London. Hopefully this chapter will help those having trouble thinking in a functional manner to solve…
Erlang being a language built for high reliability, it is natural for it to have exceptions. This chapter focuses on how to handle and raise exceptions in the functional subset of Erlang. I go over compile-time errors and warning, run-time errors, the difference between errors, exits and throws, the different constructs to handle these and then finally, an example of how to use throws for…
Time for another chapter, this time I'm covering higher order functions. I'm showing the syntax of anonymous functions, how to use them. Then, as promised in the recursion chapter, we're going to see how to use higher order functions and anonymous functions to build abstractions letting us avoid worrying about recursion. Lambdas, funs, maps, filters and folds are on the menu!
I've added a new chapter to Learn You Some Erlang. This one's about recursion and tail recursion and explains how to work in a language without looping constructs of any kind. We visit common operations such as calculating factorials (yeah, every functional programming tutorials does that), finding the length of a list, reversing, slicing and zipping lists. I also added an example in, which is…
The next three chapters of the tutorial are online: Modules, Syntax in Functions and Types (or lack thereof). We'll see how to write modules and the functions that go in them, compile our code for the Erlang VM. Then functions are pushed a bit further: we explore more pattern matching, define what guards are, learn to write conditional expressions and to convert types.
The first three chapters of the tutorial are online: Introduction, Starting Out and Starting Out (for real). We describe Erlang, install the language and VM, visit basic functions of the shell and learn about most of the basic data types of the language.