1 21 22 package org.armedbear.lisp; 23 24 public final class simple_list_remove_duplicates extends Primitive1 26 { 27 private simple_list_remove_duplicates() 28 { 29 super("simple-list-remove-duplicates", PACKAGE_SYS, false, "list"); 30 } 31 32 public LispObject execute(LispObject list) throws ConditionThrowable 33 { 34 LispObject result = NIL; 35 while (list != NIL) { 36 LispObject item = list.car(); 37 boolean duplicate = false; 38 LispObject tail = list.cdr(); 39 while (tail != NIL) { 40 if (item.eql(tail.car())) { 41 duplicate = true; 42 break; 43 } 44 tail = tail.cdr(); 45 } 46 if (!duplicate) 47 result = new Cons(item, result); 48 list = list.cdr(); 49 } 50 return result.nreverse(); 51 } 52 53 private static final Primitive1 SIMPLE_LIST_REMOVE_DUPLICATES = 54 new simple_list_remove_duplicates(); 55 } 56 | Popular Tags |