/** * FunList FrameWork. * @dependency IFunAlgo */ public abstract class FunListFW { public abstract Integer car(); public abstract FunListFW cdr(); public abstract Object execute (IFunAlgo algo, Object input); } public class EmptyFW extends FunListFW { private static EmptyFW _instance = new EmptyFW (); private EmptyFW () { } public static EmptyFW Singleton () { return _instance; } public Integer car() { throw new java.util.NoSuchElementException ("Empty has no element."); } public FunListFW cdr() { throw new java.util.NoSuchElementException ("Empty has no tail."); } public Object execute (IFunAlgo algo, Object input) { return algo.forEmpty (this, input); } } public class ConsFW extends FunListFW { private Integer _car; /** @SBGen Variable (,,,64) */ private FunListFW _cdr; public ConsFW( Integer car, FunListFW cdr ) { _car = car; _cdr = cdr; } public Integer car() { return _car; } public FunListFW cdr() { return _cdr; } public Object execute (IFunAlgo algo, Object input) { return algo.forCons (this, input); } } /** * @dependency FunListFW uses */ public interface IFunAlgo { public abstract Object forEmpty(EmptyFW list, Object input); public abstract Object forCons(ConsFW list, Object input); } public class SumAlgo implements IFunAlgo { private static SumAlgo _instance = new SumAlgo (); private SumAlgo () { } public static SumAlgo Singleton () { return _instance; } public Object forEmpty (EmptyFW list, Object input) { return new Integer (0); } public Object forCons (ConsFW list, Object input) { Integer carInt = list.car (); Integer tailSumInt = (Integer)list.cdr ().execute (this, null); return new Integer ( carInt.intValue () + tailSumInt.intValue ()); } } /** * @dependency FunListFW uses * @dependency IFunAlgo uses */ public class Client { public static void main (String[] args){ FunListFW l = new ConsFW (new Integer (5), EmptyFW.Singleton ()); System.out.println ("Sum is " + l.execute (SumAlgo.Singleton (), null)); try { System.out.println ("Press Enter to quit..."); System.in.read (); } catch (Exception e){ } } }