Avoid newbie record redundancy?

Andrew Lentvorski bsder@REDACTED
Sun May 28 00:12:11 CEST 2006


Damien Katz wrote:
> Is the following also acceptable, both functionally
> and stylewise? I find this more readable, but most
> code I see written uses the when clause and
> is_record().
> 
> match_queue(MasterQueue) ->
>  receive
>    { msgPeerMaster, #rcdPeerMaster{} = A } ->
>       match_queue(queue:in(A, MasterQueue));
>    _ ->
>       ?elog("HELP!~n", [])
>     end.

That's nice.  I like the succinctness.  The followup message about
increased flexibility is a nice bonus.

I wish we had more extensive examples of Erlang code.  It took me about
three hours of hacking and reading in order to work out the try ... catch
syntax to throw away malformed packet messages:

receive_messages(IPSMaster) ->
    receive
	{udp, Socket, IP, InPortNo, Packet} ->
	    try binary_to_term(Packet) of
		DeserializedPacket ->
		    io:format("Got message: ~p ~p ~p ~p~n",
			      [Socket, IP, InPortNo, DeserializedPacket])
	    catch
		error:badarg ->
		    io:format("Caught throw error:badarg ~n", [])
	    end,
	    receive_messages(IPSMaster)
    end.

-a



More information about the erlang-questions mailing list