<html><head></head><body>If you ever come back to this problem, let me suggest is_longer/2 as a little more readable alternative. And to make it even more useful let it accept iolists.<br><br><div class="gmail_quote">On 21 September 2016 16:30:33 GMT+10:00, Raimo Niskanen <raimo+erlang-questions@erix.ericsson.se> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">On Tue, Sep 20, 2016 at 03:53:55PM -0700, Kenneth Lakin wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> On 09/20/2016 08:00 AM, Raimo Niskanen wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"> 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 /></blockquote> <br /> That seems easy enough to fix:<br /> <br /> when length(I) =< 13 andalso (length(I) == 10 orelse length(I) == 13)<br /></blockquote><br />Sorry about being unclear. I should have written "... *called* (twice) ..."<br />since there is little greater harm in calling it twice than calling it once.<br />It is still O(N) if you call it a constant number of times, and the<br />subsequent times it is likely that data is in the processor's cache<br />so they
may be faster.<br /><br />The harm is in calling length/1 even once on a possibly very long list.<br /><br />We have had a suggestion to add a guard length(List, Max)<br />or max_length(List, Max) that would stop traversal after Max elements.<br /><br />This would be O(min(length(List), Max)),<br />which is O(Max),<br />which for a constant Max is O(1).<br /><br />But we never got to it...<br /></pre></blockquote></div></body></html>