// Ground ::= int | bool | list // ProperStream ::= null | cons(Ground, Stream) // Stream ::= ProperStream | Suspension // Suspension ::= cons( -> ProperStream, null) // susp?: Stream -> Boolean let susp? := map l to cons?(l) & function?(first(l)); // makeSusp: ( -> ProperStream) -> Suspension makeSusp := map f to cons(f, null); in let block2 := map x,y to y; // fo: Stream -> ProperStream fo := map prom to if susp?(prom) then (first(prom))() else prom; divides := map a,b to (((b / a) * a) = b); in letrec mapStream := map f,l to let fol := fo(l); in if (fol = null) then null else cons(f(first(fol)), makeSusp(map to mapStream(f, rest(fol)))); filter := map p,l to let fol := fo(l); in if (fol = null) then null else if p(first(fol)) then filter(p, rest(fol)) else cons(first(fol), makeSusp(map to filter(p, rest(fol)))); initSeg := map l,n to if (n <= 0) then null else let fol := fo(l); in cons(first(fol), initSeg(rest(fol), (n - 1))); primes := map l to let fol := fo(l); in let l1 := filter(map x to divides(first(fol), x), rest(fol)); in cons(first(fol), makeSusp(map to primes(l1))); // oddNums: -> ProperStream oddNums := map to cons(3, makeSusp(map to mapStream(map i to (i + 2), oddNums()))); in initSeg(primes(oddNums()), 20)