package scheme2.visitor; import scheme2.*; public class GetLength implements IListAlgo { public final static GetLength Singleton = new GetLength (); private GetLength() { } /** * @param host * @param input * @return */ public Object forEmpty(AListFW host, Object input) { return new Integer (0); } /** * @param host * @param input * @return */ public Object forNonEmpty(AListFW host, Object input) { return host.getRest ().execute (new HelpGetLen (1), null); } public static void main (String[] args) { AListFW p0 = ListFWFactory.Singleton.makeEmptyList(); AListFW p1 = ListFWFactory.Singleton.makeNEList (new Integer (-5), p0); AListFW p2 = ListFWFactory.Singleton.makeNEList (new Integer (3), p1); AListFW p3 = ListFWFactory.Singleton.makeNEList (new Integer (0), p2); System.out.println ("length of p0 = " + p0.execute(GetLength.Singleton, null)); System.out.println ("length of p1 = " + p1.execute(GetLength.Singleton, null)); System.out.println ("length of p2 = " + p2.execute(GetLength.Singleton, null)); System.out.println ("length of p3 = " + p3.execute(GetLength.Singleton, null)); } }