Simple question

Richard Carlsson richardc@REDACTED
Tue Aug 28 14:18:29 CEST 2001

On Tue, 28 Aug 2001, Nico Weling wrote:

> Hi Erlang freaks,


> I need OR within an case clause. ...
> Is this possible, and if, how is the syntax.

Try this:

 	case Name of
	    X when X == peter; X == klaus; X == carsten -> 
 			io:format("Is a man~n",[]);
 	    X when X == anna; X == birgit; X == petra -> 
 			io:format("Is a woman~n", []);
 	    _ -> 
 			io:format("Is a Zombie~n", [])

In other words, in a guard, you can have a ';'-separated sequence of
alternative conditions (a disjunction), where each condition is a
','-separated sequence of boolean tests (a conjunction).

(You could also use 'if' instead of 'case' for the above.)


Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW:

More information about the erlang-questions mailing list