       stream = stream.rest()
     results
 
-  toString: ->
-    this.toArray().join(', ')
+  toString: -> @toArray().join(', ')
 
 Stream.iterate = (start, step) ->
   new Stream(start, -> Stream.iterate(step(start), step))

puts fibonacci.take_while((n) ->  n < 1000000).last()
puts()

test   = (p) -> (n) -> n % p != 0
sieve  = (s) -> new Stream(s.first, -> sieve(s.rest().select(test(s.first))))
primes = sieve(Stream.from(2))

puts "The prime numbers between 10000 and 10100:"

class Stream
  constructor: (@first, rest) ->
    if typeof(rest) == 'function'
      @rest = () -> @force_rest(rest())
    else
      @force_rest(rest)

  force_rest: (val) ->
    @rest = () -> val
    val

  take_while: (pred) ->
    if pred(@first)
