| 1 3 5 22 23 package edu.neu.ccs.jmk; 24 25 31 public class ReverseFunction 32 implements Function 33 { 34 private final static int nargs = 1; 35 36 40 public String getName() { 41 return "reverse"; 42 } 43 44 52 public Value invoke(Value[] args, StringList list) 53 throws Exception  54 { 55 if (args.length == nargs) { 56 if (StringList.isStringList(args[0])) { 57 StringList sl = (StringList)args[0]; 58 for (; sl != null; sl = sl.getRest()) 59 list = new StringList(sl.getString(), list); 60 return list; 61 } 62 else { 63 String msg = getName() 64 + ": the argument is not a string list"; 65 throw new StringListCastException(msg); 66 } 67 } 68 else { 69 String msg = "Arg count error: " + getName() + " expecting " + nargs + 70 " but got " + args.length + " arguments"; 71 throw new WrongArgCountException(msg); 72 } 73 } 74 } 75 | Popular Tags |