February 2018
Beginner
200 pages
4h 37m
English
You can think of functions as subprograms of your program. They receive an input, do some computation, and then return an output. The function body is where we write expressions to do a computation. The last expression value in the function body is the function’s output. Functions are useful for reusing expressions. Let’s start with a simple example in which we’ll build messages to say hello to Ana, John, and the world. Try typing this in your IEx:
| | iex> "Hello, Mary!" |
| | "Hello, Mary!" |
| | iex> "Hello, John!" |
| | "Hello, John!" |
| | iex> "Hello, World!" |
| | "Hello, World!" |
If we want to say hello to Alice and Mike, we could copy and paste the message and replace the names. But instead we can create a function ...
Read now
Unlock full access