<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: Structs (was RE: Record selectors)</TITLE>
</HEAD>
<BODY>
<BR>
<P><FONT SIZE=2>I'm not sure if all of this has been suggested somewhere.. and I don't have time to re-read the whole thread, but I've been thinking of how to help the situation where people would define a struct locally in two modules (with perhaps an erroneous difference in definition), and send a message containing that struct:</FONT></P>
<P><FONT SIZE=2>-module(a).</FONT>
<BR><FONT SIZE=2>-struct(msg, {header, content}).</FONT>
<BR><FONT SIZE=2>loop() -></FONT>
<BR> <FONT SIZE=2>receive</FONT>
<BR> <FONT SIZE=2>~msg{header = H, content = C}</FONT>
<BR> <FONT SIZE=2>end.</FONT>
</P>
<P><FONT SIZE=2>-module(b).</FONT>
<BR><FONT SIZE=2>-struct(msg, {header, conten}).</FONT>
</P>
<P><FONT SIZE=2>send() -></FONT>
<BR> <FONT SIZE=2>a ! ~msg{header = <<1,2,3>>, conten = <<4,5,6>>}.</FONT>
</P>
<P><FONT SIZE=2>My proposal is that structs should be made strictly local or external - just like function calls. So:</FONT>
</P>
<P><FONT SIZE=2>* Sending a locally defined struct to another module with the "same" struct also locally defined would *never* match (I see some implementation where the module name is encoded into the opaque struct type).</FONT></P>
<P><FONT SIZE=2>* In order to match an externally defined struct it would need to be imported or fully qualified:</FONT>
</P>
<P><FONT SIZE=2>-module(a).</FONT>
<BR><FONT SIZE=2>-export_struct([msg/2]).</FONT>
<BR><FONT SIZE=2>-struct(msg, {header, content}).</FONT>
<BR><FONT SIZE=2>loop() -></FONT>
<BR> <FONT SIZE=2>receive</FONT>
<BR> <FONT SIZE=2>~msg{header = H, content = C}</FONT>
<BR> <FONT SIZE=2>end.</FONT>
</P>
<P><FONT SIZE=2>-module(b).</FONT>
<BR><FONT SIZE=2>-import_struct(a, [msg/2]).</FONT>
<BR><FONT SIZE=2>send() -></FONT>
<BR> <FONT SIZE=2>a ! ~msg{header = <<1,2,3>>, content = <<4,5,6>>},</FONT>
<BR> <FONT SIZE=2>a ! ~a:msg{header = <<1,2,3>>, content = <<4,5,7>>}.</FONT>
</P>
<P><FONT SIZE=2>Overlapping named locally defined structs would behave in the same way as a name clash for modules (dunno which way round, never used import!) but generate a compiler warning.</FONT></P>
<P><FONT SIZE=2>The problem of code replacement is then no worse than for modules.</FONT>
</P>
<P><FONT SIZE=2>This would give tools like xref all the help they needed to know which struct was being referred to at any time.</FONT>
</P>
<P><FONT SIZE=2>And I would dump anonymous structs (sorry Joe).</FONT>
</P>
<P><FONT SIZE=2>I think it would then be OK to reduce runtime checking to the minimum needed to ensure emulator safety (bounds checking).</FONT></P>
<P><FONT SIZE=2>Thoughts? Particularly about the locally defined structs never matching between modules (as I do recall seeing everything else before..</FONT></P>
<P><FONT SIZE=2>Aternatively we could move wholesale to UBF :-)</FONT>
</P>
<P><FONT SIZE=2>Sean</FONT>
</P>
<BR>
<BR>
<P><B><FONT SIZE=2>NOTICE AND DISCLAIMER:</FONT></B>
<BR><B><FONT SIZE=2>This email (including attachments) is confidential. If you have received this email in error please notify the sender immediately and delete this email from your system without copying or disseminating it or placing any reliance upon its contents. We cannot accept liability for any breaches of confidence arising through use of email. Any opinions expressed in this email (including attachments) are those of the author and do not necessarily reflect our opinions. We will not accept responsibility for any commitments made by our employees outside the scope of our business. We do not warrant the accuracy or completeness of such information.</FONT></B></P>
</BODY>
</HTML>