September 2013
Intermediate to advanced
548 pages
12h 25m
English
Modules are the basic units of code in Erlang. Modules are contained in files with erl extensions and must be compiled before the code in the modules can be run. Compiled modules have the extension beam.
Before we write our first module, we’ll remind ourselves about pattern matching. All we’re going to do is create a couple of data structures representing a rectangle and a square. Then we’re going to unpack these data structures and extract the sides from the rectangle and the square. Here’s how:
| | 1> Rectangle = {rectangle, 10, 5}. |
| | {rectangle, 10, 5}. |
| | 2> Square = {square, 3}. |
| | {square, 3} |
| | 3> {rectangle, Width, Height} = Rectangle. |
| | {rectangle,10,5} |
| | 4> Width. |
| | 10 |
| | 5> Height. |
| | 5 |
| | 6> {square, Side} ... |
Read now
Unlock full access