<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I'm soaking it all in.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Question: how can we time the proposed solutions to compare performance?</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Thanks to all,</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Lloyd<br><br>Sent from my iPad</div><div><br>On Sep 20, 2016, at 11:14 AM, Pagayon, Ruel <<a href="mailto:ruel@ruel.me">ruel@ruel.me</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">Note that length(ISBN) will be called twice on this maybe very long list,</span><br style="font-size:12.8px"><span style="font-size:12.8px">and that in itself may be bad since length/1 is O(N).</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">See my do-it-with-plain-functions safer but more verbose example.</span></blockquote><div><br></div><div>Thanks for clearing that up! That definitely is a better way.</div><div><br></div><div>Cheers,</div><div>Ruel </div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><p style="font-family:arial,sans-serif;font-size:medium;margin-bottom:0.0001pt;line-height:normal"><b><span style="font-size:7.5pt;color:#236b8e;background:white">Ruel
Pagayon</span></b><span style="font-size:7.5pt;color:#236b8e;background:white"> - <a href="mailto:ruel@ruel.me" target="_blank"><span style="color:#0000cc">ruel@ruel.me</span></a></span><span style="font-size:10.0pt;color:#888888;background:white"><br></span><span style="font-size:7.5pt;font-family:Arial,sans-serif;background-color:white;background-repeat:initial initial"><font color="#666666">Platform Engineer<br></font></span><span style="color:rgb(153,153,153);font-family:Arial,sans-serif;font-size:10px;background-color:rgb(255,255,255)">Networking and Communications</span></p></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, Sep 20, 2016 at 11:00 PM, Raimo Niskanen <span dir="ltr"><<a href="mailto:raimo+erlang-questions@erix.ericsson.se" target="_blank">raimo+erlang-questions@erix.ericsson.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Sep 20, 2016 at 10:17:36PM +0800, Pagayon, Ruel wrote:<br>
> Hello Lloyd,<br>
><br>
> One thing to help optimise your code: Guards<br>
><br>
> isbn_format_valid(ISBN) when length(ISBN) == 10 orelse length(ISBN) == 13 -><br>
> [I || I <- ISBN, I < $0 orelse I > $9] == [];<br>
><br>
> isbn_format_valid(_ISBN) -><br>
> false.<br>
><br>
><br>
> This makes your "is the number equal or between 0 and 9" only be executed<br>
> if the length is 10 or 13. Reason for this, is if user inputs a very large<br>
> list, you won't have to compare every character only to find later that<br>
> it's not the right length (your machine will take the toll).<br>
<br>
</span>Note that length(ISBN) will be called twice on this maybe very long list,<br>
and that in itself may be bad since length/1 is O(N).<br>
<br>
See my do-it-with-plain-functions safer but more verbose example.<br>
<span class="im HOEnZb"><br>
--<br>
<br>
/ Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
</span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>erlang-questions mailing list</span><br><span><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></span><br><span><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a></span><br></div></blockquote></body></html>