01: package gnu.mapping;
02:
03: /**
04: * Abstract class for 0- or 1-argument Scheme procedures.
05: * Extensions must provide apply0 and apply1.
06: * @author Per Bothner
07: */
08:
09: public abstract class Procedure0or1 extends Procedure {
10:
11: public Procedure0or1() {
12: super ();
13: }
14:
15: public Procedure0or1(String n) {
16: super (n);
17: }
18:
19: public int numArgs() {
20: return 0x1000;
21: }
22:
23: public abstract Object apply0() throws Throwable;
24:
25: public abstract Object apply1(Object arg1) throws Throwable;
26:
27: public Object apply2(Object arg1, Object arg2) {
28: throw new WrongArguments(this , 2);
29: }
30:
31: public Object apply3(Object arg1, Object arg2, Object arg3) {
32: throw new WrongArguments(this , 3);
33: }
34:
35: public Object apply4(Object arg1, Object arg2, Object arg3,
36: Object arg4) {
37: throw new WrongArguments(this , 4);
38: }
39:
40: public Object applyN(Object[] args) throws Throwable {
41: if (args.length == 0)
42: return apply0();
43: else if (args.length == 1)
44: return apply1(args[0]);
45: else
46: throw new WrongArguments(this, args.length);
47: }
48: }
|