[erlang-questions] style question - best way to test multiple non-guard conditions sequentially

Richard A. O'Keefe ok@REDACTED
Tue Jul 9 00:12:05 CEST 2013

On 8/07/2013, at 8:35 PM, Anthony Ramine wrote:

> No this example was just confusing, what I meant is that if you need a warning "no clause will ever match" in the case of an explicit "case foobar of true -> ok; false -> ok end" and a warning "this clause will crash" in the case of "cond foobar -> ok; true -> ok end". There is no rewording that makes the warning fit in both situations, they need to be handled separately.

In the English text here you have an "if" with no consequent.

	case foobar of true -> ok ; false -> ok end

Yes, it is appropriate to say "No matching clause" here.

As for

	cond foobar -> {ok,1} ; true-> {ok,2} end

this should *BE*

	case foobar
          of true -> {ok,1}
           ; false -> case true of true -> {ok,2} end

and no error message is appropriate here because there
*is* a clause that will match and be selected.  It is only
true that the two situations need separate handling because
one of them is not an error.

Another not-entirely-unreasonable translation of

	cond C1 -> B1 ; ... ; Cn -> Bn end

would be

	case (C1 andalso true)
	  of true -> B1
           ; false -> ...
		case (Cn andalso true)
		  of true -> Bn

and in this case you might just possibly get a warning from
the compiler that might just possibly actually be useful
(unlike 'this clause will crash'): you might be told
"expression cannot be Boolean".

It could *never* be appropriate to say "this clause will crash"
for the simple reason that it's *not* the clause that would
crash but the *condition* of the clause.  "This condition cannot
be Boolean" might make sense, but not the other.

More information about the erlang-questions mailing list