Problem 1: Fix the Bug II (100pts)

Write a procedure filter-stream, which takes a predicate f and a stream s, and returns a new stream containing only elements of the stream that satisfy the predicate. The output should contain the elements in the same order that they appeared in the original stream. You can assume there are as least one element satisfies f if s is an infinite stream.

Look at the following implementation of filter-stream, what's wrong with it?

Note: We do NOT provide ok tests for this problem, but you can write your own tests in tests/filter-stream.py.

(define (filter-stream f s)
  (if (null? s) nil
      (let ((rest (filter-stream f (cdr-stream s))))
        (if (f (car s))
            (cons-stream (car s) rest)
            rest))))