[erlang-questions] parameterized modules alternative in chicago boss like use case

Tim Watson watson.timothy@REDACTED
Mon Jul 4 09:53:34 CEST 2011


> Alternative to pmods in that case could be records, proplist/dict, gen_server.
>
> - records
>
> To use a record, we need to tell the template about the record type.
> {% for p#product in products %}
> That's fine but we can only use the same template for several model types
> if the records of all product types have the same structure:
> {product_type1, {name, price, some_field}}
> {product_type2, {name, price, another_field}}
> We can't 'extend' a record in erlang so we'll have to manually make write the structure of all related records which will be hard in a large application.
>

You could extend (or rewrite) something like
https://github.com/esl/parse_trans/blob/master/doc/exprecs.md to
export a bunch of functions associated with the record. This stuff
works at compile time (using parse transforms) but could be achieved
at runtime with a bit of beam munging.



More information about the erlang-questions mailing list