[erlang-questions] Question about order of matching

Allen McPherson mcpherson@REDACTED
Wed Mar 4 02:17:37 CET 2009

I have the following receive loop:

getResults(0) ->
     'getResults ok';
getResults(N) ->
	{Test, ET, N, Bytes, Pid} ->
	    io:format("~p: ET: ~p~n", [Test, ET]),
	'unknown test' ->
	    io:format("unknown test~n"),
	Any ->
	    io:format("~p~n", [Any]),

When it is sent the following message:

MasterPid ! {allpairs, timer(wall_clock), N, Bytes, self()},

..the Any clause (which I put in for debugging purposes because nothing
was matching and the receive was blocking) matches and prints the  


I would have thought the first clause should have matched?
I tested in the shell:

(foo@REDACTED)1> {Test, ET, N, Bytes, Pid} = {allpairs, 
  1: syntax error before: '<'

The shell does not like the Pid syntax and I've Googled around to see  
why this
is a problem even when using pid_to_list and list_to_pid.
This works though:

(foo@REDACTED)1> {Test, ET, N, Bytes, Pid} = {allpairs, 

And, removing Pid in shell works too:

(foo@REDACTED)1> {Test, ET, N, Bytes} = {allpairs,2346,100,1048576}.

The same tactic (removing Pid) in the code still matches the Any clause.

Perhaps I'm not understanding something fundamental here?  I suspect  
this is
a dumb mistake on my part but I can't see it.


More information about the erlang-questions mailing list