01: package kawa.standard;
02:
03: import gnu.lists.*;
04: import gnu.mapping.*;
05:
06: /**
07: * Implement the Scheme extended function "vector-append".
08: * @author Per Bothner
09: */
10:
11: public class vector_append extends ProcedureN {
12: public static final vector_append vectorAppend = new vector_append(
13: "vector-append");
14:
15: public vector_append(String name) {
16: super (name);
17: }
18:
19: public Object applyN(Object[] args) {
20: return apply$V(args);
21: }
22:
23: public static FVector apply$V(Object[] args) {
24: int length = 0;
25: int args_length = args.length;
26: for (int i = args_length; --i >= 0;) {
27: Object arg = args[i];
28: if (arg instanceof FVector)
29: length += ((FVector) arg).size();
30: else {
31: int n = LList.listLength(arg, false);
32: if (n < 0)
33: throw new WrongType(vectorAppend, i, arg,
34: "list or vector");
35: length += n;
36: }
37: }
38: Object[] result = new Object[length];
39: int position = 0;
40: for (int i = 0; i < args_length; i++) {
41: Object arg = args[i];
42: if (arg instanceof FVector) {
43: FVector vec = (FVector) arg;
44: int vec_length = vec.size();
45: for (int j = 0; j < vec_length; j++)
46: result[position++] = vec.get(j);
47: } else if (arg instanceof Pair) {
48: while (arg != LList.Empty) {
49: Pair pair = (Pair) arg;
50: result[position++] = pair.car;
51: arg = pair.cdr;
52: }
53: }
54: }
55: return new FVector(result);
56: }
57: }
|