Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/elixir/pages/Guards.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ Other constructs are `for`, `with`, `try`/`rescue`/`catch`/`else`/, and the `mat

## Failing guards

Errors in guards do not result in a runtime error, but in the erroring guard fail. For example, the `length/1` function only works with lists, and if we use it on anything else it fails:
Errors in guards do not result in runtime errors, but in guards failing. For example, the `length/1` function only works with lists. If we use it with anything else, a runtime error is raised:

```elixir
iex> length("hello")
** (ArgumentError) argument error
```

However, when used in guards, it simply makes the corresponding clause fail (i.e., not match):
However, when used in guards, the corresponding clause simply fails to match:

```elixir
iex> case "hello" do
Expand All @@ -123,7 +123,7 @@ iex> case "hello" do
:length_failed
```

In many cases, we can take advantage of this: in the code above, for example, we can use `length/1` to both check that the given thing is a list *and* check some properties of its length (instead of using `is_list(something) and length(something) > 0`).
In many cases, we can take advantage of this. In the code above, we used `length/1` to both check that the given thing is a list *and* check some properties of its length (instead of using `is_list(something) and length(something) > 0`).

## Expressions in guard clauses

Expand Down