[erlang-questions] Correct syntax of a case clause

Joel Reymont <>
Sun Jun 14 20:35:25 CEST 2009


On Jun 14, 2009, at 6:58 PM, info wrote:

> case Expr of
> a,b -> block1;        % if Expr = a or b then block1
>   c -> block2         % if Expr = c then block2
> end
>
> (a,b) gives an error

As it should.

> What is the correct syntax ?


{a, b}

For example...

1> foo:main().
check({1,2}) = got_1
check(3) = got_2
ok

-module(foo).

-compile([export_all]).

check(X) ->
	case X of
		{_, _}	-> got_1;
		_	-> got_2
	end.

main() ->
	io:format("check(~p) = ~p~n", [{1, 2}, check({1, 2})]),	
	io:format("check(~p) = ~p~n", [3, check(3)]).

---
Mac hacker with a performance bent
http://www.linkedin.com/in/joelreymont



More information about the erlang-questions mailing list