Created
March 26, 2013 09:43
-
-
Save sudowork/5244196 to your computer and use it in GitHub Desktop.
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
| -module(ex_if). | |
| -export([is_42/1, always_true/0]). | |
| % contrived example | |
| is_42(Num) -> | |
| if | |
| Num =:= 42 -> true; | |
| true -> false | |
| end. | |
| always_true() -> | |
| if | |
| false, true -> nevertrue; | |
| false; true -> alwaystrue; % we always evaluate to this one | |
| true -> alsoalwaystrue % this never gets matched because the previous guard is always true | |
| end. | |
| %----- ERLANG SHELL -----% | |
| 1> c(ex_if). | |
| ex_if.erl:13: Warning: the guard for this clause evaluates to 'false' | |
| ex_if.erl:15: Warning: this clause cannot match because a previous clause at line 14 always matches | |
| {ok,ex_if} | |
| 2> ex_if:is_42(42). | |
| true | |
| 3> ex_if:is_42(not42). | |
| false | |
| 4> ex_if:always_true(). | |
| alwaystrue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment