1 package kawa.standard; 2 import gnu.mapping.*; 3 import gnu.lists.*; 4 5 9 10 public class append extends ProcedureN 11 { 12 public static final append append = new append(); 13 static { append.setName("append"); } 14 15 public Object applyN (Object [] args) 16 { 17 return append$V(args); 18 } 19 20 public static Object append$V (Object [] args) 21 { 22 int count = args.length; 23 if (count == 0) 24 return LList.Empty; 25 Object result = args[count - 1]; 26 for (int i = count - 1; --i >= 0; ) 27 { 28 Object list = args[i]; 29 Object copy = null; 30 Pair last = null; 31 while (list instanceof Pair) 32 { 33 Pair list_pair = (Pair) list; 34 Pair new_pair = new Pair (list_pair.car, null); 35 if (last == null) 36 copy = new_pair; 37 else 38 last.cdr = new_pair; 39 last = new_pair; 40 list = list_pair.cdr; 41 } 42 if (list != LList.Empty) 43 throw new WrongType(append, i+1, args[i], "list"); 44 if (last != null) 45 { 46 last.cdr = result; 47 result = copy; 48 } 49 } 50 return result; 51 } 52 } 53 | Popular Tags |