[erlang-questions] New module syntax and semantics?
Christian S
chsu79@REDACTED
Wed Jul 2 02:06:50 CEST 2008
2008/7/1 Juan Jose Comellas <juanjo@REDACTED>:
> The good thing about this feature is that it provides a way to have an
> "encapsulated" record replacement.
> The code that receives the events is unnecessary cumbersome because it needs
> to work with a record within a record. If this was encapsulated within a
> parameterized module, it would become much cleaner.
Nested records are not nice, no. For the record:
make_stuff() ->
#fs_channel_event{extra=#fs_channel_answer_event{write_codec_name=rot13}}.
set_stuff(Ex) ->
Ex2 = Ex#fs_channel_event{extra=(Ex#fs_channel_event.extra)#fs_channel_answer_event{read_codec_name=leetspeak}}.
So the verbose syntax to do the above is what you want to avoid.
Did you consider using an approach like the following instead?
AnswerEvent = {#fs_channel_event{}, #fs_answer_event{}}
HangupEvent = {#fs_channel_event{}, #fs_hangup_event{}}
It's easy to deconstruct a tuple in pattern matching. You dont get the
nesting above.
make_stuff() ->
{#fs_channel_event{}, #fs_channel_answer_event{write_codec_name=rot13}}.
set_stuff({A, B}) ->
{A, B#fs_channel_answer_event{read_codec_name=leetspeak}}.
More information about the erlang-questions
mailing list