<div>
All makes sense, although for know I'll continue do describe it as evilness ;)
</div><div><br></div><div>Cheers,</div><div><br></div><div>Steve</div>
<div><div><br></div><div>-- </div><div>Steve Strong</div><div>Sent with <a href="http://www.sparrowmailapp.com/?sig">Sparrow</a></div><div><br></div></div>
<p style="color: #A0A0A8;">On Friday, 8 February 2013 at 23:36, Steve Vinoski wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div><br><br><div>On Fri, Feb 8, 2013 at 5:09 PM, Steve Strong <span dir="ltr"><<a href="mailto:steve@srstrong.com" target="_blank">steve@srstrong.com</a>></span> wrote:<br><blockquote type="cite"><div>
<div>
Hi,
</div><div><br></div><div>I've got a binary split that I'm doing fairly regularly, so I wanted to use a compiled pattern to make it more efficient. I don't have any state floating around (it's very much a utility function), so my plan was to compile the pattern in an erl shell and just paste the resultant term directly into my source code (with an appropriate comment!). However, things are not as they seem:</div>
<div><br></div><div><div><font face="Courier New">Erlang R15B02 (erts-5.9.2) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">Eshell V5.9.2 (abort with ^G)</font></div>
<div><font face="Courier New">1> C = binary:compile_pattern(<<0,0,1,0>>).</font></div><div><font face="Courier New">{bm,<<>>}</font></div></div></div></blockquote><div><br></div><div>On the Erlang binary module man page (<a href="http://www.erlang.org/doc/man/binary.html">http://www.erlang.org/doc/man/binary.html</a>) it describes the return value of compile_pattern as follows:</div>
<div><br></div><div>"Opaque data-type representing a compiled search-pattern. Guaranteed to be a tuple() to allow programs to distinguish it from non precompiled search patterns."</div><div><br></div><div>The binary:compile_pattern function is a BIF that creates a "magic binary", much like the resources one can create in a NIF, and these appear as empty binaries in Erlang code as you can see in your shell output, but they're really opaque data types. Because of this, your approach won't work because the subsequent functions you're calling think you're passing an actual empty binary instead of the required opaque type.</div>
<div><br></div><div>--steve</div></div>
</div></div></span>
</blockquote>
<div>
<br>
</div>