Skip to content

Commit

Permalink
Slightly clarify why guards
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 25, 2023
1 parent 4cac7af commit ba2e569
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/elixir/pages/references/patterns-and-guards.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Suffix matches (`hello <> " world"`) are not valid patterns.

Guards are a way to augment pattern matching with more complex checks. They are allowed in a predefined set of constructs where pattern matching is allowed, such as function definitions, case clauses, and others.

Not all expressions are allowed in guard clauses, but only a handful of them. This is a deliberate choice. This way, Elixir (and Erlang) can make sure that nothing bad happens while executing guards and no mutations happen anywhere. It also allows the compiler to optimize the code related to guards efficiently.
Not all expressions are allowed in guard clauses, but only a handful of them. This is a deliberate choice. This way, Elixir (through Erlang) ensures that all guards are predictable (no mutations or other side-effects) and they can be optimized and performed efficiently.

### List of allowed functions and operators

Expand Down

0 comments on commit ba2e569

Please sign in to comment.