[erlang-questions] New module syntax and semantics?

Juan Jose Comellas juanjo@REDACTED
Tue Jul 1 22:59:52 CEST 2008

The good thing about this feature is that it provides a way to have an
"encapsulated" record replacement.

I have a library that I have built that acts as a client to FreeSWITCH (an
open source telephony switch). I'm connected to FS over a socket where I get
telephony events in an HTTP-like text protocol. These events have lots of
fields (sometimes over 50) so it's necessary to keep their information in
records. The problem is that some of these events share some fields. To
avoid code duplication I use one function to parse common fields and another
one to parse event-specifc data. To make this work I keep the channel data
in a record and in a field of this record I keep another record with the
event-specific data.

For example, whenever a channel is answered or hung up I get an event. As
these two events are related to a channel, they share some fields, which I
keep in an fs_channel_event record. This record has a field called 'extra'
where I keep another record with the fields that are not common. These are a
simplified version of the records:

% Generic channel event.
-record(fs_channel_event, {
          %% Field where we keep a fs_channel_answer_event or a
          %% fs_channel_hangup_event.

% Channel answer event.
-record(fs_channel_answer_event, {

% Channel hangup event.
-record(fs_channel_hangup_event, {

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.

On Tue, Jul 1, 2008 at 11:59 AM, Christian S <chsu79@REDACTED> wrote:

> 2008/7/1 Juan Jose Comellas <juanjo@REDACTED>:
> > An does anybody know what would it take to make this feature
> > official/supported? It is really useful in some cases.
> Can you provide examples of how it is useful?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080701/7d444a58/attachment.htm>

More information about the erlang-questions mailing list