Child modules draft feedback wanted
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Fri Mar 31 11:21:38 CEST 2006
Romain Lenglet wrote:
>
> Why not have a specific construct or convention to get record
> information at a module level (not at a source code level,
> like -record). For instance, for behaviour, the functions to
> implement are specified in the behaviour module as a function:
> behaviour_info/1. What not have a similar record_info/1
> function??? That function would return the list of field
> names (as atoms) for the record name given as an atom as an argument.
>
> E.g.:
>
> -module(record_spec).
> -export([record_info/1]).
> record_info(record1) ->
> [field1, field2];
> record_info(record2) ->
> [field1, field2, field3].
>
This was basically proposed by Mats Cronqvist not long ago:
http://www.erlang.org/ml-archive/erlang-questions/200509/msg00260.html
Since it is not allowed today to define a function
record_info/1 in a module, it would be very easy to have the
compiler generate and export such a function, rather than
providing it only as a pseudo-function.
> And in using modules, we could use a modified -record construct:
> -record(Module, RecordName).
> It would be like an "import of record definition". E.g.:
> -record(record_spec, record1).
I would prefer -use_record or -import_record, to avoid
overloading.
/Ulf W
More information about the erlang-questions
mailing list