You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function declarations also support guards and multiple clauses. If a function has several clauses, Elixir will try each clause until it finds one that matches. Here is an implementation of a function that checks if the given number is zero or not:
Giving an argument that does not match any of the clauses raises an error.
128
126
129
127
## Function capturing
130
128
131
-
Throughout this tutorial, we have been using the notation `name/arity` to refer to functions. It happens that this notation can actually be used to retrieve a named function as a function type. Let's start `iex` and run the `math.exs` file defined above:
129
+
Throughout this tutorial, we have been using the notation `name/arity` to refer to functions. It happens that this notation can actually be used to retrieve a named function as a function type. Let's edit `math.exs` to look like this:
130
+
131
+
```elixir
132
+
defmoduleMathdo
133
+
defzero?(0), do:true
134
+
defzero?(x) whenis_number(x), do:false
135
+
end
136
+
```
137
+
138
+
And start `iex`, running the `math.exs` file defined above:
0 commit comments