Browse Source

Introducing Erlang highlights

master
Julio Biason 4 years ago
parent
commit
5581f8669b
  1. 44
      content/reviews/books/introducing-erlang.md

44
content/reviews/books/introducing-erlang.md

@ -1,6 +1,7 @@
+++
title = "Introducing Erlang: Getting Started in Functional Programming - Simon St. Laurent"
date = 2020-08-05
updated = 2020-10-26
[taxonomies]
tags = ["books", "reviews", "simon st laurent", "erlang", "it",
@ -34,3 +35,46 @@ 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.
## Highlights
> 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).
> -module(drop).<br>
> -export([fall_velocity/1, mps_to_mph/1, mps_to_kph/1]).<br><br>
> fall_velocity(Distance) -> math:sqrt(2 * 9.8 * Distance). <br>
> mps_to_mph(Mps) -> 2.23693629 * Mps.<br>
> mps_to_kph(Mps) -> 3.6 * Mps.
> -module(combined).<br>
> -export([height_to_mph/1]).<br>
> -import(drop, [fall_velocity/1]).<br>
> -import(convert, [mps_to_mph/1]).<br>
> 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 =<. Dont make them look like arrows.
> try <br>
> math:sqrt(2 * Gravity * Distance) <br>
> catch <br>
> error:Error -> {error, Error} end.
> Creating a map requires a different syntax presenting keys and values:<br>
> 1> Planemos = #{ earth => 9.8, moon => 1.6, mars => 3.71 }.<br>
> #{earth => 9.8,mars => 3.71,moon => 1.6}

Loading…
Cancel
Save