Skip to content

Instantly share code, notes, and snippets.

@elbow-jason
Last active August 29, 2015 14:22
Show Gist options
  • Save elbow-jason/d2e01e137c46f9c495e5 to your computer and use it in GitHub Desktop.
Save elbow-jason/d2e01e137c46f9c495e5 to your computer and use it in GitHub Desktop.
pattern_matching_warnings
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