// file: integers.java // author: Robert Keller // purpose: test lazy evaluation using integers // To test main use: java -cs integers import polya.*; import java.io.*; import java.util.*; class integers extends Growable { static public Polylist nats = Polylist.cons(new Long(0), new Incremental(new integers(1))); // integers reuses the Growable long n; // The numeric "seed" for the integers from n integers(long n) { this.n = n; } public Object grow() { Long value = new Long(n); n++; return Polylist.cons(value, new Incremental(this)); } public static void main(String[] arg) { System.out.println(nats); System.out.println(nats.prefix(10)); System.out.println(nats); System.out.println(nats.prefix(20)); System.out.println(nats); System.out.println(nats.prefix(20).coprefix(10)); } }