Skip to content

Commit bd92cba

Browse files
Improve defguard/1 docs with links to guides (#13757)
1 parent 1b73c49 commit bd92cba

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/elixir/lib/kernel.ex

+15-11
Original file line numberDiff line numberDiff line change
@@ -5696,16 +5696,15 @@ defmodule Kernel do
56965696
end
56975697

56985698
@doc """
5699-
Generates a macro suitable for use in guard expressions.
5699+
Defines a macro suitable for use in guard expressions.
57005700
5701-
It raises at compile time if the definition uses expressions that aren't
5702-
allowed in guards, and otherwise creates a macro that can be used both inside
5703-
or outside guards.
5701+
It raises at compile time if the `guard` uses expressions that aren't
5702+
allowed in [guard clauses](patterns-and-guards.html#guards),
5703+
and otherwise creates a macro that can be used both inside or outside guards.
57045704
5705-
Note the convention in Elixir is to prefix all guards that return a boolean
5706-
with the `is_` prefix, such as `is_list/1`. If, however, the function/macro
5707-
returns a boolean and is not allowed in guards, it should have no prefix and
5708-
end with a question mark, such as `Keyword.keyword?/1`.
5705+
When defining your own guards, consider the
5706+
[naming conventions](naming-conventions.html#is_-prefix-is_foo)
5707+
around boolean-returning guards.
57095708
57105709
## Example
57115710
@@ -5742,12 +5741,17 @@ defmodule Kernel do
57425741
end
57435742

57445743
@doc """
5745-
Generates a private macro suitable for use in guard expressions.
5744+
Defines a private macro suitable for use in guard expressions.
57465745
5747-
It raises at compile time if the definition uses expressions that aren't
5748-
allowed in guards, and otherwise creates a private macro that can be used
5746+
It raises at compile time if the `guard` uses expressions that aren't
5747+
allowed in [guard clauses](patterns-and-guards.html#guards),
5748+
and otherwise creates a private macro that can be used
57495749
both inside or outside guards in the current module.
57505750
5751+
When defining your own guards, consider the
5752+
[naming conventions](naming-conventions.html#is_-prefix-is_foo)
5753+
around boolean-returning guards.
5754+
57515755
Similar to `defmacrop/2`, `defguardp/1` must be defined before its use
57525756
in the current module.
57535757
"""

0 commit comments

Comments
 (0)