Skip to content

Commit 1d13d18

Browse files
author
José Valim
committed
Document that ^ always points to the previous value
1 parent 7fcdecd commit 1d13d18

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ defmodule Kernel.SpecialForms do
480480
defmacro __DIR__
481481

482482
@doc """
483-
Access an already bound variable in match clauses.
483+
Accesses an already bound variable in match clauses.
484484
485485
## Examples
486486
@@ -499,7 +499,14 @@ defmodule Kernel.SpecialForms do
499499
iex> ^x = 2
500500
** (MatchError) no match of right hand side value: 2
501501
502-
Note the `^` special form is only useful in matches.
502+
Note that `^` always refers to the value of x prior to the match. The
503+
following example will match:
504+
505+
iex> x = 0
506+
iex> { x, ^x } = { 1, 0 }
507+
iex> x
508+
1
509+
503510
"""
504511
defmacro ^(var)
505512

0 commit comments

Comments
 (0)