Introducing Erlang: Getting Started in Functional Programming - Simon St. Laurent

GoodReads Summary: 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.


Again, an "Introducing" book that one shouldn't expect some deep explanations, but heck, this felt shallower than Introducing Elixir.

It follows the same path of the "Introducing Elixir" (or maybe it is the other way around, but hey, that's the order I read both), by creating a "what speed will something crash if dropped in different planets" library and exploring changes.

But the biggest drawback is that the book sticks too much into the Erlang Shell and absolutely nothing (besides "here is one thing you can search for") outside it. I mean, sure, the language may be nice and fun and all that, but what's the point if the build tool is a pain and dependency resolution is inexistent -- and I'm not saying Erlang suffers from that, 'cause as a learning path, the book says nothing about those things.

For seeing how the language looks like, it's a good book. For something more real... far away from it.


go to the command line and type erl

Note: erl is the Erlang Shell.

3> 2#1010111.

Note: Binary notation.

4> 16#cafe

Note: Hex notation.

FallVelocity = fun(Distance) -> math:sqrt(2 * 9.8 * Distance) end.

Note: fun creates an anonymous function; it is then associated with the name FallVelocity (all variables need to start with an upcase letter).

-export([fall_velocity/1, mps_to_mph/1, mps_to_kph/1]).

fall_velocity(Distance) -> math:sqrt(2 * 9.8 * Distance).
mps_to_mph(Mps) -> 2.23693629 * Mps.
mps_to_kph(Mps) -> 3.6 * Mps.

-import(drop, [fall_velocity/1]).
-import(convert, [mps_to_mph/1]).
height_to_mph(Meters) -> mps_to_mph(fall_velocity(Meters)).

In Erlang, greater-than-or-equal-to is written as >=, and less-than-or-equal-to as =<. Don’t make them look like arrows.

math:sqrt(2 * Gravity * Distance)
error:Error -> {error, Error} end.

Creating a map requires a different syntax presenting keys and values:
1> Planemos = #{ earth => 9.8, moon => 1.6, mars => 3.71 }.
#{earth => 9.8,mars => 3.71,moon => 1.6}