<div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 30, 2012 at 10:47 AM, José Valim <span dir="ltr"><<a href="mailto:jose.valim@gmail.com" target="_blank">jose.valim@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
At the beginning of this year, there was a discussion about how to implement binary_to_integer/1 in Erlang.<div>There is a possible implementation for such function which is quite trivial:</div><div><br></div><div> list_to_integer(binary_to_list(binary))</div>
<div><br></div><div>However, it has the trade-off that it can't be used in guards (unless defined in a macro) and there is an unnecessary conversion cost to list (although the cost is small since both binary and list are likely small).</div>
<div><br></div><div>With Riak, Cowboy and other tools pushing towards using binaries instead of lists for strings, the need for such functions will become more and more common.</div><div>Is there any chance we will see this as built-in functions and therefore available in guards in R16?</div>
</blockquote><div><br></div>I think this is a good proposal. We've already got these functions for atoms, numbers make sense too. I find myself implementing this often one way or another, sometimes just using a JSON parser and checking that the result is the kind of number I'm looking for.</div>
<div class="gmail_quote"><br><div>-bob</div><div> </div></div></div>