title: List is conceived as integer by length function
body: <p>I'm trying to learn Erlang using the <a href="http://codekata.pragprog.com/2007/01/kata_two_karate.html" rel="nofollow noreferrer">Karate Chop Kata</a>. I translated the runit test supplied in the kata to an eunit test and coded up a small function to perform the task at hand. </p>
  
  <pre><code>-module(chop).
  -export([chop/2]).
  -import(lists).
  -include_lib("eunit/include/eunit.hrl").
  -ifdef(TEST).
  chop_test_() -&gt; [
      ?_assertMatch(-1, chop(3, [])),
      ?_assertMatch(-1, chop(3, [1])),
      ?_assertMatch(0,  chop(1, [1])),
   ....several asserts deleted for brevity...
  ].
  -endif.
  
  chop(N,L) -&gt; chop(N,L,0);
  chop(_,[]) -&gt; -1.
  chop(_, [],_) -&gt; -1;
  chop(N, L, M) -&gt;
      MidIndex = length(L) div 2,
      MidPoint = lists:nth(MidIndex,L),
      {Left,Right} = lists:split(MidIndex,L),
      case MidPoint of 
      _ when MidPoint &lt; N -&gt; chop(N,Right,M+MidIndex);
      _ when MidPoint =:= N -&gt; M+MidIndex;
      _ when MidPoint &gt; N -&gt; chop(N,Left,M)
      end.
  </code></pre>
  
  <p>Compiles ok.Running the test however gives, (amongst others) the following failure:</p>
  
  <pre><code>::error:badarg
   in function erlang:length/1
    called as length(1)
   in call from chop:chop/3
  </code></pre>
  
  <p>I've tried different permutations of declaring chop(N,[L],M) .... and using length([L]) but have not been able to resolve this issue. Any suggestions are welcome. </p>
  
  <p>ps. As you might have guessed I'm a nube when it comes to Erlang.</p>