Last active
August 29, 2015 14:22
-
-
Save elbow-jason/d2e01e137c46f9c495e5 to your computer and use it in GitHub Desktop.
pattern_matching_warnings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def passwords_match?(_x, _x), do: true | |
def passwords_match?(_, _), do: false | |
# causes the following warning... | |
# registration.ex:61: warning: the underscored variable "_x" appears more | |
# than once in a match. This means the pattern will only match | |
# if all "_x" bind to the same value. If this is the intended behaviour, | |
# please remove the leading underscore from the variable name, | |
# otherwise give the variables different names | |
# versus | |
def passwords_match?(x, x), do: true | |
def passwords_match?(_, _), do: false | |
# this issues no warning about unused variables even though x is not is | |
# matched/bound, not "ignored" (read: underscored), and not used. | |
# Why does the second example with `x` not cause warnings? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment