October 2014
Intermediate to advanced
280 pages
7h 20m
English
Let’s look at two ways to compile this file and load it into iex. First, if you’re at the command line, you can do this:
| | $ iex times.exs |
| | iex> Times.double 4 |
| | 8 |
Give iex a source file’s name, and it compiles and loads the file before it displays a prompt.
If you’re already in iex, you can use the c helper to compile your file without returning to the command line.
| | iex> c "times.exs" |
| | [Times] |
| | iex> Times.double(4) |
| | 8 |
| | iex> Times.double(123) |
| | 246 |
The line c "times.exs" compiles your source file and loads it into iex. We then call the double function in the Times module a couple of times using Times.double.
What happens if we make our function fail by passing it a string rather than a number?
| | iex> Times.double( ... |
Read now
Unlock full access