Skip to content

Commit 4362e33

Browse files
eksperimentalJosé Valim
authored and
José Valim
committed
Rename h and t vars to head and tail (#1340)
1 parent e0a9e52 commit 4362e33

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

_posts/2013-05-23-elixir-v0-9-0-released.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ defimpl Enumerable, for: List do
7777
do_reduce(list, acc, fun)
7878
end
7979

80-
defp do_reduce([h | t], acc, fun) do
81-
do_reduce(t, fun.(h, acc), fun)
80+
defp do_reduce([head | tail], acc, fun) do
81+
do_reduce(tail, fun.(head, acc), fun)
8282
end
8383

8484
defp do_reduce([], acc, fun) do

crash-course.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ Pattern matching in Elixir is based on Erlang's implementation and in general is
454454
**Erlang**
455455

456456
```erlang
457-
loop_through([H | T]) ->
458-
io:format('~p~n', [H]),
459-
loop_through(T);
457+
loop_through([Head | Tail]) ->
458+
io:format('~p~n', [Head]),
459+
loop_through(Tail);
460460

461461
loop_through([]) ->
462462
ok.
@@ -465,9 +465,9 @@ loop_through([]) ->
465465
**Elixir**
466466

467467
```elixir
468-
def loop_through([h | t]) do
469-
IO.inspect h
470-
loop_through t
468+
def loop_through([head | tail]) do
469+
IO.inspect head
470+
loop_through tail
471471
end
472472

473473
def loop_through([]) do

getting-started/pattern-matching.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ iex> tail
104104
Similar to the `hd/1` and `tl/1` functions, we can't match an empty list with a head and tail pattern:
105105

106106
```iex
107-
iex> [h | t] = []
107+
iex> [head | tail] = []
108108
** (MatchError) no match of right hand side value: []
109109
```
110110

@@ -164,9 +164,9 @@ iex> {x, x} = {1, 2}
164164
In some cases, you don't care about a particular value in a pattern. It is a common practice to bind those values to the underscore, `_`. For example, if only the head of the list matters to us, we can assign the tail to underscore:
165165

166166
```iex
167-
iex> [h | _] = [1, 2, 3]
167+
iex> [head | _] = [1, 2, 3]
168168
[1, 2, 3]
169-
iex> h
169+
iex> head
170170
1
171171
```
172172

0 commit comments

Comments
 (0)