<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.E-postmall17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=SV link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span lang=EN-US>I’ve found some behaviour that I didn’t
expect in binary_to_term in R12B. I’m testing the QuickCheck property<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>prop_binary_to_term()
-><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
?FORALL(Bin,binary(),<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
case catch binary_to_term(Bin) of<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'> {'EXIT',{badarg,_}}
-><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
true;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'> Term
-><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
Bins = term_to_binaries(Term),<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
?WHENFAIL(io:format("~p~n~p~n",[Term,Bins]),<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
lists:any(fun(Bin2)->Bin=:=Bin2 end,Bins))<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
end).<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>term_to_binaries(T)
-><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
lists:usort([term_to_binary(T,[{compressed,Level},{minor_version,Ver}])<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'> ||
Level <- lists:seq(0,9),<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
Ver <- [0,1]]).<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>binary()
-><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'>
?LET(L,list(choose(0,255)),<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Courier New"'> list_to_binary(L)).<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>The property says that any binary that
binary_to_term successfully decodes, must be an encoding of that term using
some compression level and minor version (the encoding options mentioned in the
documentation). But it fails, on, for example:<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US><<131,97,0,0>><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>0<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>[<<131,97,0>>]<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>Or<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US><<131,106,0>><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>[]<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>[<<131,106>>]<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>Or<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US><<131,106,191,1,69,44,184,180,64>><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>[]<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>[<<131,106>>]<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>Or<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US><<131,67,0>><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>'_'<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>[<<131,100,0,1,95>>]<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>where the output in each case is the binary,
the term it decodes to, and the list of all possible encodings produced by
term_to_binary.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>Is this a bug?<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>John<o:p></o:p></span></p>
</div>
</body>
</html>