diff options
author | Brett Beatty <brettbeatty@gmail.com> | 2019-10-02 23:37:57 -0600 |
---|---|---|
committer | Fernando Tapia Rico <fertapric@gmail.com> | 2019-10-03 07:37:57 +0200 |
commit | 0f5585dab8028808fbc4f2197bc508b947a386a9 (patch) | |
tree | d7c10a50beb635dd61c1e33cf9e65d3770af1f87 | |
parent | 860f03f4c9a7bf137f73a7bf4aff15385972a275 (diff) | |
download | elixir-0f5585dab8028808fbc4f2197bc508b947a386a9.tar.gz |
Update docs for Kernel.SpecialForms.case/2 (#9378)
-rw-r--r-- | lib/elixir/lib/kernel/special_forms.ex | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/elixir/lib/kernel/special_forms.ex b/lib/elixir/lib/kernel/special_forms.ex index f97bad1c8..0a91c7b6c 100644 --- a/lib/elixir/lib/kernel/special_forms.ex +++ b/lib/elixir/lib/kernel/special_forms.ex @@ -1737,8 +1737,7 @@ defmodule Kernel.SpecialForms do ## Variable handling - Notice that variables bound in a clause "head" do not leak to the - outer context: + Notice that variables bound in a clause do not leak to the outer context: case data do {:ok, value} -> value @@ -1748,8 +1747,8 @@ defmodule Kernel.SpecialForms do value #=> unbound variable value - However, variables explicitly bound in the clause "body" are - accessible from the outer context: + When binding variables with the same names as variables in the outer context, + the variables in the outer context are not affected. value = 7 @@ -1759,12 +1758,11 @@ defmodule Kernel.SpecialForms do end value - #=> 7 or 13 + #=> 7 - In the example above, `value` is going to be `7` or `13` depending on - the value of `lucky?`. In case `value` has no previous value before - case, clauses that do not explicitly bind a value have the variable - bound to `nil`. + In the example above, `value` is going to be `7` regardless of the value of + `lucky?`. The variable `value` bound in the clause and the variable `value` + bound in the outer context are two entirely separate variables. If you want to pattern match against an existing variable, you need to use the `^/1` operator: |