[erlang-questions] If Condition vs. Multiple Function Clauses

Richard A. O'Keefe ok@REDACTED
Mon Jun 17 01:19:31 CEST 2013


On 16/06/2013, at 1:30 AM, Steve Davis wrote:

> Yep, that would be a better, more consistent way to go...
> 
> if  M == N -> a();
>     M > N -> b();
>     _ -> c()
> end.

Let's see, this says
	"Should the test M == N succeed, compute a().
	 Otherwise, should the test M >N succeed, compute b().
	 Otherwise, take a new variable that has never been given
	 any value whatsoever; should that variable, contrary to
	 all sane expectation, somehow magically turn out to be
	 bound to a succeeding test, compute c()."

Just how is the "_" supposed to get a value here?

By the way, anyone who is really suffering from the lack of 'else'
can just
	-define(else, true).
and then
	if M < N -> c()
	 ; M > N -> b()
	 ; ?else -> a()
	end
and be done with it, although putting M == N there instead would
make it more obvious to one's readers, should one _have_ readers.




More information about the erlang-questions mailing list