1 package gnu.kawa.functions; 2 import gnu.math.*; 3 import gnu.mapping.*; 4 import gnu.text.Char; 5 import gnu.expr.*; 6 7 8 9 public class IsEqv extends Procedure2 implements CanInline 10 { 11 Language language; 12 IsEq isEq; 13 14 public IsEqv(Language language, String name, IsEq isEq) 15 { 16 this.language = language; 17 this.isEq = isEq; 18 setName(name); 19 } 20 21 public static boolean apply (Object arg1, Object arg2) 22 { 23 if (arg1==arg2) 24 return true; 25 if (arg1 instanceof Char || arg1 instanceof Numeric 26 || arg1 instanceof Symbol) 28 return arg1.equals (arg2); 29 return false; 30 } 31 32 public Object apply2 (Object arg1, Object arg2) 33 { 34 return language.booleanObject(apply(arg1, arg2)); 35 } 36 37 private static boolean nonNumeric(Expression exp) 38 { 39 if (exp instanceof QuoteExp) 40 { 41 Object value = ((QuoteExp) exp).getValue(); 42 return ! (value instanceof Numeric || value instanceof Char 43 || value instanceof Symbol); 44 } 45 return false; 46 } 47 48 public Expression inline (ApplyExp exp, ExpWalker walker) 49 { 50 Expression[] args = exp.getArgs(); 51 if (nonNumeric(args[0]) || nonNumeric(args[1])) 52 return new ApplyExp(isEq, args); 53 return exp; 54 } 55 } 56 | Popular Tags |