Skip to content

Commit 2551fbd

Browse files
authored
Move fun/arity explanation later in getting started (#13890)
1 parent 39d1ecb commit 2551fbd

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

lib/elixir/pages/getting-started/anonymous-functions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
Anonymous functions allow us to store and pass executable code around as if it was an integer or a string. Let's learn more.
44

5+
## Identifying functions and documentation
6+
7+
Before we move on to discuss anonymous functions, let's talk about how Elixir identifies named functions.
8+
9+
Functions in Elixir are identified by both their name and their arity. The arity of a function describes the number of arguments that the function takes. From this point on we will use both the function name and its arity to describe functions throughout the documentation. `trunc/1` identifies the function which is named `trunc` and takes `1` argument, whereas `trunc/2` identifies a different (nonexistent) function with the same name but with an arity of `2`.
10+
11+
We can also use this syntax to access documentation. The Elixir shell defines the [`h`](`IEx.Helpers.h/1`) function, which you can use to access documentation for any function. For example, typing `h trunc/1` is going to print the documentation for the `trunc/1` function:
12+
13+
```elixir
14+
iex> h trunc/1
15+
def trunc(number)
16+
17+
Returns the integer part of number.
18+
```
19+
20+
`h trunc/1` works because it is defined in the `Kernel` module. All functions in the `Kernel` module are automatically imported into our namespace. Most often you will also include the module name when looking up the documentation for a given function:
21+
22+
```elixir
23+
iex> h Kernel.trunc/1
24+
def trunc(number)
25+
26+
Returns the integer part of number.
27+
```
28+
29+
You can use the module+function to lookup for anything, including operators (try `h Kernel.+/2`). Invoking [`h`](`IEx.Helpers.h/1`) without arguments displays the documentation for `IEx.Helpers`, which is where `h` and other functionalities are defined.
30+
531
## Defining anonymous functions
632

733
Anonymous functions in Elixir are delimited by the keywords `fn` and `end`:

lib/elixir/pages/getting-started/basic-types.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,6 @@ false
8181

8282
You can also use [`is_float`](`is_float/1`) or [`is_number`](`is_number/1`) to check, respectively, if an argument is a float, or either an integer or float.
8383

84-
## Identifying functions and documentation
85-
86-
Before we move on to the next data type, let's talk about how Elixir identifies functions.
87-
88-
Functions in Elixir are identified by both their name and their arity. The arity of a function describes the number of arguments that the function takes. From this point on we will use both the function name and its arity to describe functions throughout the documentation. `trunc/1` identifies the function which is named `trunc` and takes `1` argument, whereas `trunc/2` identifies a different (nonexistent) function with the same name but with an arity of `2`.
89-
90-
We can also use this syntax to access documentation. The Elixir shell defines the `h` function, which you can use to access documentation for any function. For example, typing `h trunc/1` is going to print the documentation for the `trunc/1` function:
91-
92-
```elixir
93-
iex> h trunc/1
94-
def trunc(number)
95-
96-
Returns the integer part of number.
97-
```
98-
99-
`h trunc/1` works because it is defined in the `Kernel` module. All functions in the `Kernel` module are automatically imported into our namespace. Most often you will also include the module name when looking up the documentation for a given function:
100-
101-
```elixir
102-
iex> h Kernel.trunc/1
103-
def trunc(number)
104-
105-
Returns the integer part of number.
106-
```
107-
108-
You can use the module+function to lookup for anything, including operators (try `h Kernel.+/2`). Invoking `h` without arguments displays the documentation for `IEx.Helpers`, which is where `h` and other functionality is defined.
109-
11084
## Booleans and `nil`
11185

11286
Elixir supports `true` and `false` as booleans:

0 commit comments

Comments
 (0)