Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Why are records not 'export'-able?

Received: by 10.205.134.138 with SMTP id ic10mr327768bkc.8.1340983642504;
        Fri, 29 Jun 2012 08:27:22 -0700 (PDT)
X-BeenThere: erlang-programming@googlegroups.com
Received: by 10.204.129.85 with SMTP id n21ls3919224bks.6.gmail; Fri, 29 Jun
 2012 08:27:22 -0700 (PDT)
Received: by 10.205.134.138 with SMTP id ic10mr327764bkc.8.1340983641982;
        Fri, 29 Jun 2012 08:27:21 -0700 (PDT)
Received: by 10.205.134.138 with SMTP id ic10mr327763bkc.8.1340983641952;
        Fri, 29 Jun 2012 08:27:21 -0700 (PDT)
Return-Path: <erlang-questions-boun...@erlang.org>
Received: from hades.cslab.ericsson.net (hades.cslab.ericsson.net. [192.121.151.104])
        by gmr-mx.google.com with ESMTP id iv15si2333833bkc.0.2012.06.29.08.27.21;
        Fri, 29 Jun 2012 08:27:21 -0700 (PDT)
Received-SPF: pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) client-ip=192.121.151.104;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) smtp.mail=erlang-questions-boun...@erlang.org
Received: from hades.cslab.ericsson.net (hades [192.121.151.104])
	by hades.cslab.ericsson.net (Postfix) with ESMTP id 4253A5C1D5;
	Fri, 29 Jun 2012 17:27:14 +0200 (CEST)
X-Original-To: erlang-questi...@erlang.org
Delivered-To: erlang-questi...@erlang.org
Received: from zimbra.erlangsystems.com (zimbra.erlangsystems.com
 [93.93.131.195])
 by hades.cslab.ericsson.net (Postfix) with ESMTP id 93D205C011
 for <erlang-questi...@erlang.org>; Fri, 29 Jun 2012 17:27:12 +0200 (CEST)
Received: from localhost (localhost.localdomain [127.0.0.1])
 by zimbra.erlangsystems.com (Postfix) with ESMTP id 2BF7F182E00E;
 Fri, 29 Jun 2012 16:27:12 +0100 (BST)
X-Virus-Scanned: amavisd-new at zimbra.erlangsystems.com
Received: from zimbra.erlangsystems.com ([127.0.0.1])
 by localhost (zimbra.erlangsystems.com [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id kvAGmB-BDR-z; Fri, 29 Jun 2012 16:27:11 +0100 (BST)
Received: from zimbra.erlangsystems.com (zimbra.erlangsystems.com
 [93.93.131.195])
 by zimbra.erlangsystems.com (Postfix) with ESMTP id D514A182E001;
 Fri, 29 Jun 2012 16:27:10 +0100 (BST)
Date: Fri, 29 Jun 2012 16:27:10 +0100 (BST)
From: Robert Virding <robert.vird...@erlang-solutions.com>
To: Mahesh Paolini-Subramanya <mah...@dieswaytoofast.com>
Message-ID: <495b5f26-3eee-4263-b9dd-d1d6456dc111@knuth>
In-Reply-To: <8367670F-7092-4618-ADF7-EF0843BF6...@dieswaytoofast.com>
MIME-Version: 1.0
X-Originating-IP: [193.11.11.78]
X-Mailer: Zimbra 7.1.1_GA_3196 (ZimbraWebClient - FF3.0 (Mac)/7.1.1_GA_3196)
Cc: Erlang Questions <erlang-questi...@erlang.org>
Subject: Re: [erlang-questions] Why are records not 'export'-able?
X-BeenThere: erlang-questi...@erlang.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: General Erlang/OTP discussions <erlang-questions.erlang.org>
List-Unsubscribe: <http://erlang.org/mailman/options/erlang-questions>,
 <mailto:erlang-questions-requ...@erlang.org?subject=unsubscribe>
List-Archive: <http://erlang.org/pipermail/erlang-questions>
List-Post: <mailto:erlang-questi...@erlang.org>
List-Help: <mailto:erlang-questions-requ...@erlang.org?subject=help>
List-Subscribe: <http://erlang.org/mailman/listinfo/erlang-questions>,
 <mailto:erlang-questions-requ...@erlang.org?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============7953396518207367090=="
Errors-To: erlang-questions-boun...@erlang.org
Sender: erlang-questions-boun...@erlang.org

--===============7953396518207367090==
Content-Type: multipart/alternative;
 boundary="=_1825927d-d971-41a3-8260-29881c5cab1b"

--=_1825927d-d971-41a3-8260-29881c5cab1b
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

The main reason is that records are purely compile-time and record definitions only exist in the compiler. At runtime a record is just a normal tuple with nothing in it to show that it came from a record or what the record definition is. So there are no problems accessing record as tuples and tuples as records, though in most cases it is a stupid thing to do. 

So the problem is that you need to be able to access the record definition whenever a module using it is compiled. One solution is to put the record definition .hrl file in an applications include directory. It is then possible to access that file from the compiler using: 

-include_lib("app/include/recdef.hrl"). 

The compiler will extend the app name with version numbers when necessary. 

Robert 

----- Original Message -----

> 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.

> 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)'

> The more realistic me says "There is probably some reason why you
> can't do this. Probably has to do with compilers. It usually does".

> Anyone?

> Mahesh Paolini-Subramanya
> That Tall Bald Indian Guy...
> Blog | Twitter | Google+

> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions

--=_1825927d-d971-41a3-8260-29881c5cab1b
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head><style type=3D'text/css'>p { margin: 0; }</style></head><body><=
div style=3D'font-family: Times New Roman; font-size: 12pt; color: #000000'=
>The main reason is that records are purely compile-time and record definit=
ions only exist in the compiler. At runtime a record is just a normal tuple=
 with nothing in it to show that it came from a record or what the record d=
efinition is. So there are no problems accessing record as tuples and tuple=
s as records, though in most cases it is a stupid thing to do.<br><br>So th=
e problem is that you need to be able to access the record definition whene=
ver a module using it is compiled. One solution is to put the record defini=
tion .hrl file in an applications include directory. It is then possible to=
 access that file from the compiler using:<br><br>-include_lib("app/include=
/recdef.hrl").<br><br>The compiler will extend the app name with version nu=
mbers when necessary.<br><br>Robert<br><br><hr id=3D"zwchr"><blockquote sty=
le=3D"border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5=
px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;fon=
t-family:Helvetica,Arial,sans-serif;font-size:12pt;">If I have a record I u=
se in just one module, I declare it in that module.<div>If I have a record =
I use across a number of modules, I declare it in an included&nbsp;file.</d=
iv><div>If I have a record that I use across a number of applications, I en=
d up declaring it once in each application.</div><div><br></div><div>The si=
mple-minded me says "Hmf. If I could just have a '-export_record' declarati=
on, then I could do some fun things like '-record(Name, Application:Record)=
'</div><div><br></div><div>The more realistic me says "There is probably so=
me reason why you can't do this. Probably has to do with compilers. It usua=
lly does".</div><div><br></div><div>Anyone?</div><div><br><div>
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; color:=
 rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: no=
rmal; font-weight: normal; letter-spacing: normal; line-height: normal; orp=
hans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizonta=
l-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorati=
ons-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-wi=
dth: 0px; font-size: medium; "><span class=3D"Apple-style-span" style=3D"bo=
rder-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-=
variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; t=
ext-align: -webkit-auto; text-indent: 0px; text-transform: none; white-spac=
e: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing:=
 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-eff=
ect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; =
font-size: medium; "><div style=3D"word-wrap: break-word; -webkit-nbsp-mode=
: space; -webkit-line-break: after-white-space; "><span class=3D"Apple-styl=
e-span" style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-famil=
y: Helvetica; font-variant: normal; letter-spacing: normal; line-height: no=
rmal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transfor=
m: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-=
horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text=
-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-=
stroke-width: 0px; font-size: medium; "><div style=3D"word-wrap: break-word=
; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span =
class=3D"Apple-style-span" style=3D"border-collapse: separate; color: rgb(0=
, 0, 0); font-variant: normal; letter-spacing: normal; line-height: normal;=
 orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: no=
ne; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horiz=
ontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-deco=
rations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-strok=
e-width: 0px; font-size: medium; "><div style=3D"word-wrap: break-word; -we=
bkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class=
=3D"Apple-style-span" style=3D"border-collapse: separate; color: rgb(0, 0, =
0); font-variant: normal; letter-spacing: normal; line-height: normal; orph=
ans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; w=
hite-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal=
-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decoratio=
ns-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-wid=
th: 0px; font-size: medium; "><div style=3D"word-wrap: break-word; -webkit-=
nbsp-mode: space; -webkit-line-break: after-white-space; "><span class=3D"A=
pple-style-span" style=3D"border-collapse: separate; color: rgb(0, 0, 0); f=
ont-variant: normal; letter-spacing: normal; line-height: normal; orphans: =
2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-=
space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spac=
ing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in=
-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0=
px; font-size: medium; "><div style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space; "><span class=3D"Apple-=
style-span" style=3D"border-collapse: separate; font-variant: normal; lette=
r-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-aut=
o; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; =
word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-v=
ertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-tex=
t-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-w=
rap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-=
space; "><span class=3D"Apple-style-span" style=3D"border-collapse: separat=
e; font-variant: normal; letter-spacing: normal; line-height: normal; orpha=
ns: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; wh=
ite-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-=
spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decoration=
s-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-widt=
h: 0px; "><div><span class=3D"Apple-style-span" style=3D"border-collapse: s=
eparate; font-variant: normal; letter-spacing: normal; line-height: normal;=
 orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: no=
ne; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horiz=
ontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-deco=
rations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-strok=
e-width: 0px; "><div style=3D"word-wrap: break-word; -webkit-nbsp-mode: spa=
ce; -webkit-line-break: after-white-space; "><div><div><span class=3D"Apple=
-style-span" style=3D"-webkit-text-decorations-in-effect: underline; "><spa=
n class=3D"Apple-style-span" style=3D"border-collapse: separate; font-varia=
nt: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-a=
lign: -webkit-auto; text-indent: 0px; text-transform: none; white-space: no=
rmal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px;=
 -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: =
none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><di=
v><div style=3D"font-family: Helvetica; margin-top: 0in; margin-right: 0in;=
 margin-left: 0in; margin-bottom: 0.0001pt; "><font class=3D"Apple-style-sp=
an" color=3D"#1f497d" face=3D"Calibri, sans-serif"><span class=3D"Apple-sty=
le-span" style=3D"font-size: 15px; "><div style=3D"margin-top: 0px; margin-=
right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal norma=
l 15px/normal Calibri; color: rgb(31, 73, 125); "><div style=3D"margin-top:=
 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal=
 normal normal 15px/normal Calibri; color: rgb(1, 108, 226); "><div style=
=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0p=
x; font: normal normal normal 15px/normal Calibri; color: rgb(1, 108, 226);=
 "><b><i><div style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0=
px; margin-left: 0px; font: normal normal normal 15px/normal Calibri; color=
: rgb(1, 108, 226); "><a href=3D"http://www.gravatar.com/avatar/204a87f81a0=
d9764c1f3364f53e8facf.png" target=3D"_blank"><b><i>Mahesh Paolini-Subramany=
a</i></b></a></div><div style=3D"margin-top: 0px; margin-right: 0px; margin=
-bottom: 0px; margin-left: 0px; font: normal normal normal 15px/normal Cali=
bri; color: rgb(31, 73, 125); ">That Tall Bald Indian Guy...</div><div styl=
e=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0=
px; font: normal normal normal 15px/normal Calibri; color: rgb(1, 108, 226)=
; "><span style=3D"text-decoration: underline; "><a href=3D"http://dieswayt=
oofast.blogspot.com/" target=3D"_blank">Blog</a></span><span class=3D"Apple=
-converted-space">&nbsp;</span>&nbsp;<span class=3D"Apple-converted-space">=
&nbsp;</span><span style=3D"color: rgb(31, 73, 125); ">|<span class=3D"Appl=
e-converted-space">&nbsp;</span>&nbsp;<span class=3D"Apple-converted-space"=
>&nbsp;</span><a href=3D"https://twitter.com/dieswaytoofast" target=3D"_bla=
nk"><span style=3D"text-decoration: underline; color: rgb(1, 108, 226); ">T=
witter</span></a><span class=3D"Apple-converted-space">&nbsp;</span>&nbsp;<=
span class=3D"Apple-converted-space">&nbsp;</span>|<span class=3D"Apple-con=
verted-space">&nbsp;</span>&nbsp;<span class=3D"Apple-converted-space">&nbs=
p;</span><a href=3D"https://plus.google.com/u/0/108074935470209044442/posts=
" target=3D"_blank"><span style=3D"text-decoration: underline; color: rgb(1=
, 108, 226); ">Google+</span></a></span></div></i></b></div></div></div></s=
pan></font></div></div></span></span></div></div></div></span></div></span>=
<font class=3D"Apple-style-span" style=3D"color: rgb(0, 0, 0); font-family:=
 Helvetica; font-size: medium; font-style: normal; font-weight: normal; " f=
ace=3D"Calibri"><div style=3D"margin-top: 0px; margin-right: 0px; margin-bo=
ttom: 0px; margin-left: 0px; font: normal normal normal 15px/normal Calibri=
; color: rgb(6, 63, 244); font-size: 15px; "><u></u></div></font></div></sp=
an></div></span></div></span></div></span></div></span></div></span></span>=

</div>

<br></div><br>_______________________________________________<br>erlang-que=
stions mailing list<br>erlang-questi...@erlang.org<br>http://erlang.org/mai=
lman/listinfo/erlang-questions<br></blockquote><br></div></body></html>
--=_1825927d-d971-41a3-8260-29881c5cab1b--

--===============7953396518207367090==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

--===============7953396518207367090==--