lists:keymember

Samuel Rivas <>
Tue Nov 9 11:57:15 CET 2004


  I see the performance issue. What surprised me was the fact that the
function call did not fail even when the whole list had to be traversed.
In a "let-it-crash" approach I would have implemented that function as

keymember(_K, _N, []) ->
    false;
keymember(K, N, [H|T]) ->
    case element(N, H) of
         K -> {value, H};
         _ -> keymember(K, N, T)
    end.

  I see the behaviour of the OTP implementation is achieved by means of a
guard instead of the case block, but I found the result a little astonishing.
Perhaps I am going too far in my "crashing-all" philosophy :)

  Regards
-- 
	Samuel



More information about the erlang-questions mailing list