Last active
December 20, 2015 08:39
-
-
Save tosik/6101740 to your computer and use it in GitHub Desktop.
why does elixir output the warning 'variable x is unused' ?
This file contains hidden or 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
| % elixir main.exs | |
| > unused_x_variableain.exs:4: variable x is unused | |
| > foo |
This file contains hidden or 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
| defmodule Main do | |
| def match(x) do | |
| case :foo do | |
| x -> 'foo' | |
| _ -> 'bar' | |
| end | |
| end | |
| end | |
| IO.puts Main.match(:foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
twitterで見かけました。
elixirはパターンマッチで再束縛されちゃうので、それだとxは任意の値にマッチしてしまいます。
意図をつかみそこねてなければたぶん正しくはこうです。