[erlang-questions] Inheriting functions that use record atoms

Tristan Sloughter tristan.sloughter@REDACTED
Sat Jul 9 15:28:03 CEST 2011


I will have a number of modules that define a single record and functions
for using that record as a model stored in a database for a webapp.

There are these nice macros for converting a record to json and json to a
record that will basically always look like:

to_json(Record) ->
    ?record_to_json(?MODULE, Record).

to_record(JSON) ->
    ?json_to_record(?MODULE, JSON).

But at times they'll need to be overridden for a specific module/record.

My problem is I'd like to not have to copy/paste these into every module
(and they'll be more base functions like these) that is a model. extends
would be best since that allows overriding but from the base module I can't
reference the module that is inheriting the base module as a macro, so I
can't use the json_to_record macro since I can't pass in a macro of the
record atom name.

A parse transform won't work either since I don't think I can add a call to
a macro like I need.

Does anyone have any suggestions? Or should I just not use records for this?
Records are nice since I'm using mnesia and found those record_to json_to
macros!

Thanks,
Tristan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110709/204d7ec6/attachment.htm>


More information about the erlang-questions mailing list