| 1 package gnu.q2.lang; 2 import gnu.mapping.*; 3 import gnu.lists.*; 4 import gnu.expr.*; 5 import java.util.Vector ; 6 7 public class Q2Apply extends MethodProc 8 { 9 public static Q2Apply q2Apply = new Q2Apply(); 10 11 public void apply (CallContext ctx) throws Throwable  12 { 13 Object endMarker = Special.dfault; 14 Object arg = ctx.getNextArg(endMarker); 15 if (arg instanceof Procedure) 16 { 17 Procedure proc = (Procedure) arg; 18 Vector vec = new Vector (); 19 for (;;) 20 { 21 arg = ctx.getNextArg(endMarker); 22 if (arg == endMarker) 23 break; 24 if (arg instanceof Values) 25 { 26 Object [] vals = ((Values) arg).getValues(); 27 for (int i = 0; i < vals.length; i++) 28 vec.add(vals[i]); 29 } 30 else 31 vec.add(arg); } 33 arg = proc.applyN(vec.toArray()); 34 if (arg instanceof Consumable) 35 ((Consumable) arg).consume(ctx.consumer); 36 else 37 ctx.writeValue(arg); 38 return; 39 } 40 for (;;) 41 { 42 if (arg == endMarker) 43 break; 44 if (arg instanceof Consumable) 45 ((Consumable) arg).consume(ctx.consumer); 46 else 47 ctx.writeValue(arg); 48 arg = ctx.getNextArg(endMarker); 49 } 50 } 51 52 67 } 68 | Popular Tags |