/**
 * This file is part of Erjang - A JVM-based Erlang VM
 *
 * Copyright (c) 2009 by Trifork
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/


package erjang.m.lists;

import erjang.BIF;
import erjang.ENative;
import erjang.EObject;
import erjang.NotImplemented;

public class Native extends ENative {

	@BIF
	public static EObject keyfind(EObject o1, EObject o2, EObject o3) {
		throw new NotImplemented();		
	}
	
}

@@ -745,16 +745,99 @@
 Object;%0A
+import erjang.ERT;%0Aimport erjang.ESeq;%0Aimport erjang.ESmall;%0Aimport erjang.ETuple;%0A
 import e
@@ -947,10 +947,11 @@
 ect 
-o1
+key
 , EO
@@ -960,10 +960,15 @@
 ect 
-o2
+nth_arg
 , EO
@@ -977,45 +977,516 @@
 ect 
-o3) %7B%0A%09%09throw new NotImplemented
+list_arg) %7B%0A%09%09ESmall nth = nth_arg.testSmall();%0A%09%09ESeq list = list_arg.testSeq();%0A%09%09%0A%09%09if (key == null %7C%7C nth == null %7C list == null)%0A%09%09%09%09throw ERT.badarg(key, nth_arg, list_arg);%0A%0A%09%09while (!list.isNil()) %7B%0A%09%09%09EObject elm = list.head();%0A%09%09%09ETuple tup = elm.testTuple();%0A%0A%09%09%09// test that it is a tuple of the right size%0A%09%09%09if (tup != null && tup.arity() %3E= nth.value) %7B%09%09%09%09%0A%09%09%09%09EObject val = tup.elm(nth.value);%0A%09%09%09%09if (val.equals(key)) %7B return tup; %7D%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09list = list.tail
 ();
+%0A
 %09%09
+%7D%0A%0A%09%09return ERT.FALSE;
 %0A%09%7D%0A

implement lists:keyfind/3 BIF