[erlang-questions] Web Sockets on Yaws/ewgi

Davide Marquês nesrait@REDACTED
Sat Dec 19 20:16:10 CET 2009

Hi Zoltan,

May I ask you what is the reason of not using Erlang records in ewgi? You
> seem to be reimplementing record handling there on purpose.
> Using records would render most of your getter/setter macros and functions
> unnecessary saving you a few hundred lines of code.

I'm a later arrival at the ewgi party, but I can tell there was a lot of
care in designing the specification [1]. :)
At this point (I think the following is still accurate) the representation
matches records and parametrized modules. And using the words of others [2]:

> 3. I have come to like the spec as it is now as the record definition
>> really
>> gives the implementor a set of options, you can
> 3.a access fields through tuple pattern matching, or
>> element(N,ewgi_request)
>> 3.b access fields using records
>> 3.c access field using the API access functions (and creating responses)
>> 3.d write a parameterized module mapping with the same name as the record
>> and use getters and setters or other functions (like in Mochiweb). If you
>> have a record like
>> -record(ewgi_response, {
>>           status,
>>           headers=[],
>>           message_body,
>>           err
>>          }).
>> you can write a parameterized module
>> -module(ewgi_response, [Status, Headers, MessageBody, Err]).
>> -export([get_status/0])
>> get_status() -> Status
>> If you then create a record A=#ewgi_response{status=?OK} you can use it as
>> parameterized module with A:get_status(), as far as I understood it. Kind
>> of
>> a dual nature.
When receiving a ewgi_context() you can treat in any one of those different
ways. The advantage of using the provided functions is that your code
becomes future proof.

Also the API would be much more straightforward to use. At least for me :).
We'll have to agree on disagreeing on that one. ;)

[1] you can follow the various developments over at

Davide :)

More information about the erlang-questions mailing list