 <p>(I've tried to edit @false's <a href="http://stackoverflow.com/a/15140312/1545971">response</a>, but it was rejected)</p> <p><code>my_len_tail/2</code> is faster (in terms of both the number of inferences and actual time) than buldin <code>length/2</code> when generating a list, but has problem with <code>N in 1..2</code> constraint.</p> <pre><code>?- time(( my_len_tail(L,N),N=10000000 )). % 20,000,002 inferences, 2.839 CPU in 3.093 seconds (92% CPU, 7044193 Lips) L = [_G67, _G70, _G73, _G76, _G79, _G82, _G85, _G88, _G91|...], N = 10000000 . ?- time(( length(L,N),N=10000000 )). % 30,000,004 inferences, 3.557 CPU in 3.809 seconds (93% CPU, 8434495 Lips) L = [_G67, _G70, _G73, _G76, _G79, _G82, _G85, _G88, _G91|...], N = 10000000 . </code></pre>