[erlang-questions] Why are records not 'export'-able?

Richard O'Keefe ok@REDACTED
Mon Jul 2 03:19:49 CEST 2012


On 30/06/2012, at 2:06 AM, Mahesh Paolini-Subramanya wrote:

> If I have a record I use in just one module, I declare it in that module.
> If I have a record I use across a number of modules, I declare it in an included file.
> If I have a record that I use across a number of applications, I end up declaring it once in each application.

Er, what stops you using the same -include file in more than one application?

If I found myself wanting to use the same -record in more than one
application, I'd lie down until the feeling wore off.  More precisely,
I'd definitely want to hide that inside some sort of access module.
> 
> The simple-minded me says "Hmf. If I could just have a '-export_record' declaration, then I could do some fun things like '-record(Name, Application:Record)'

But there is no _thing_ for it to bind to.  Records are just a kind of macro
that the compiler understands.

With frames, there'd be no -record declaration in the first place, you'd just
use the data like you can just use a list or tuple.

With abstract patterns, you'd import them from the defining module the way
you'd import ordinary functions from their defining module.

Records are *neither* a data type *nor* something function-like.

Consider the following module:

-module(foo).
-export([bar/2]).

-record(ugh, {ugh}).

bar(i, #ugh{ugh=X}) -> #ugh{ugh=X+1};
bar(d, {ugh,Y})     -> {ugh,Y-1}.

To me, it looks like a very bad idea to use both record syntax
and plain tuple syntax for the same kind of data.  I think that
if there is a -record declaration for a record name, and there
is also any tuple with the same name as its first element, the
compiler should warn about that.  Currently it doesn't.





More information about the erlang-questions mailing list