01: package gnu.q2.lang;
02:
03: import gnu.mapping.*;
04: import gnu.lists.*;
05: import gnu.expr.*;
06: import java.util.Vector;
07:
08: public class Q2Apply extends MethodProc {
09: public static Q2Apply q2Apply = new Q2Apply();
10:
11: public void apply(CallContext ctx) throws Throwable {
12: Object endMarker = Special.dfault;
13: Object arg = ctx.getNextArg(endMarker);
14: if (arg instanceof Procedure) {
15: Procedure proc = (Procedure) arg;
16: Vector vec = new Vector();
17: for (;;) {
18: arg = ctx.getNextArg(endMarker);
19: if (arg == endMarker)
20: break;
21: if (arg instanceof Values) {
22: Object[] vals = ((Values) arg).getValues();
23: for (int i = 0; i < vals.length; i++)
24: vec.add(vals[i]);
25: } else
26: vec.add(arg); // requires collections FIXME
27: }
28: arg = proc.applyN(vec.toArray());
29: if (arg instanceof Consumable)
30: ((Consumable) arg).consume(ctx.consumer);
31: else
32: ctx.writeValue(arg);
33: return;
34: }
35: for (;;) {
36: if (arg == endMarker)
37: break;
38: if (arg instanceof Consumable)
39: ((Consumable) arg).consume(ctx.consumer);
40: else
41: ctx.writeValue(arg);
42: arg = ctx.getNextArg(endMarker);
43: }
44: }
45:
46: /*
47: public Object applyN (Object[] args) throws Throwable
48: {
49: if (args.length == 0)
50: return Values.empty;
51: Object arg0 = args[0];
52: if (arg0 instanceof Procedure)
53: {
54: Object[] xargs = new Object[args.length-1];
55: System.arraycopy(args, 1, xargs, 0, xargs.length);
56: return ((Procedure) arg0).applyN(xargs);
57: }
58: return gnu.kawa.functions.AppendValues.appendValues.applyN(args);
59: }
60: */
61: }
|