// file: squares.java // author: Robert Keller // purpose: test lazy evaluation using squares // To test main use: java -cs squares import polya.*; import java.io.*; // Examples of creating incremental Polylists // squares does not reuse the Growable, although it could in principal class squares extends Growable { long n; squares(long n) { this.n = n; } public Object grow() { return Polylist.cons(new Long(n*n), new Incremental(new squares(n+1))); } static public void main(String []arg) { Polylist sqs = new Incremental(new squares(0)); System.out.println(sqs); System.out.println(sqs.prefix(10)); System.out.println(sqs); System.out.println(sqs.prefix(20)); System.out.println(sqs); } }