{{{ #!rst public class GnappoProduct { private static class SchemeExpressionPower implements SchemeExpression { private SchemeExpression exp1; private SchemeExpression exp2; public SchemeExpressionPower(SchemeExpression expr1, SchemeExpression expr2) { exp1=expr1; exp2=expr2; } public SchemeValue evaluate(SchemeEnvironment env) throws SchemeException { return SchemeFactoryManager.instance().create("SchemeExpressionInt", ((int)(Math.pow(exp1.evaluate(env).asInt(),exp2.evaluate(env).asInt())))).evaluate(env); } public void prettyPrint(PrintStream out) { out.print("(pow "); exp1.prettyPrint(out); out.print(" "); exp2.prettyPrint(out); out.print(")"); } } /** * @param args * @throws SchemeException */ public static void main(String[] args) throws SchemeException { // TODO Auto-generated method stub SchemeFactoryManager fm = SchemeFactoryManager.instance(); fm.put("pow", new SchemeFactory() { public SchemeExpression create(Object... args) { return new SchemeExpressionPower((SchemeExpression)args[0],(SchemeExpression)args[1]); } }); SchemeExpression power = fm.create("pow",fm.create("SchemeExpressionInt",2),fm.create("SchemeExpressionInt",4)); power.prettyPrint(System.out); System.out.println(); System.out.print(power.evaluate(null)); } } }}}