May 2018
Intermediate to advanced
412 pages
9h 3m
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