<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 1 Feb 2014, at 21:29, Max Lapshin <<a href="mailto:max.lapshin@gmail.com">max.lapshin@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="gmail_extra">Fred, your ideas are right, of course, but you forget that right now records doesn't have any infrastructure for code upgrade.</div><div class="gmail_extra"><br></div><div class="gmail_extra">The only way is to make {state, Field1, Field2, ....} mapping by hands.</div></div></blockquote><div><br></div>Actually, there *is* a framework for this, although I can’t say if anyone actually uses it.<br><blockquote type="cite"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;"></span></blockquote></div><div><br></div><div>See e.g.</div><div><a href="https://github.com/uwiger/parse_trans/blob/master/examples/test_exprecs_vsns.erl">https://github.com/uwiger/parse_trans/blob/master/examples/test_exprecs_vsns.erl</a></div><div><br></div><div>-module(test_exprecs_vsns).<br><br>-export([f/0]).<br>-export_records([r]).<br><br>-compile({parse_transform, exprecs}).<br><br>-record(r, {a,b,c}).<br>-record(r__1_2, {a,b}).<br>-record(r__1_1, {a,b,c,d}).<br><br><br>f() -><br> io:fwrite("'#info-r'(fields) -> ~p~n", ['#info-r'(fields)]),<br> io:fwrite("'#info-r__1_1'(fields)' -> ~p (not exported)~n",<br><span class="Apple-tab-span" style="white-space:pre"> </span> ['#info-r__1_1'(fields)]),<br> io:fwrite("'#info-r__1_2'(fields)' -> ~p (not exported)~n",<br><span class="Apple-tab-span" style="white-space:pre"> </span> ['#info-r__1_2'(fields)]),<br> io:fwrite("'#convert-'(\"1_1\", {r,1,2,3,4}) -> ~p~n",<br><span class="Apple-tab-span" style="white-space:pre"> </span> ['#convert-'("1_1", {r,1,2,3,4})]),<br> io:fwrite("'#convert-'(\"1_2\", {r,1,2}) -> ~p~n",<br><span class="Apple-tab-span" style="white-space:pre"> </span> ['#convert-'("1_2", {r,1,2})]).</div><div><br></div><div>** Test run:</div><div><br></div><div>Eshell V5.9.2 (abort with ^G)<br>1> c(test_exprecs_vsns).<br>{ok,test_exprecs_vsns}<br>2> test_exprecs_vsns:f().<br>'#info-r'(fields) -> [a,b,c]<br>'#info-r__1_1'(fields)' -> [a,b,c,d] (not exported)<br>'#info-r__1_2'(fields)' -> [a,b] (not exported)<br>'#convert-'("1_1", {r,1,2,3,4}) -> {{r,1,2,3},[{d,4}]}<br>'#convert-'("1_2", {r,1,2}) -> {{r,1,2,undefined},[]}<br>ok<br></div><div><div><br></div></div>** Explanation:<div><br></div><div>The record ‘r’ is “exported”, meaning that exprecs generates accessor functions for it.</div><div><br></div><div>Old versions of the record definition are kept, but renamed as r__1_1, r__1_2, etc., respectively.</div><div><br></div><div>When old versions are present, exprecs will generate a ‘#convert-‘(OldVsn, Record) function that returns a record on the current format, together with a list of element that are no longer present.</div><div><br></div><div>Note that it doesn’t _convert_ elements; it simply maps them by name.</div><div><br></div><div>I probably should document this...</div><div><br></div><div>BR,</div><div>Ulf W</div><div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><div><div>Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div><div><a href="http://feuerlabs.com">http://feuerlabs.com</a></div></div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></div></body></html>