[erlang-questions] How erlang handle complicated data structure like C?

Mike Oxford moxford@REDACTED
Thu Sep 22 20:24:56 CEST 2011


You can pattern-match non-empty records against an "empty" record.

receive_function(Packet = #my_record{}) ->
   do_something_with_my_packet(Packet);
receive_function(Packet = #my_other_record{}) ->
   do_something_else_with_my_packet(Packet);
receive_function(Packet) ->
   I_do_not_care.

-mox

On Tue, Sep 20, 2011 at 6:45 AM, Jesper Louis Andersen
<jesper.louis.andersen@REDACTED> wrote:
> On Mon, Sep 19, 2011 at 08:26, George Catalin Serbanut
> <cgsmcmlxxv@REDACTED> wrote:
>> Considering all variables integers, here is an example how to play with
>> records:
>
> I'll move the quotes around a bit...
>
>> 7. How to use the test:
>> receive_function(Packet) when is_my_record(Packet) == true ->
>> do_something_with_my_packet;
>> receive_function(Packet) when is_my_record(Packet) /= true -> I_do_not_care.
>
> You can't do this in Erlang. Guard expressions are limited so you can
> be sure they terminate.



More information about the erlang-questions mailing list