[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stream-cons



Hi,
stream-car and stream-cdr can be speeded up by writing stream-cons as follows:
 
(define-syntax stream-cons
    (syntax-rules ()
      ((stream-cons obj strm)
        (stream-eager (make-stream-pare (stream-delay obj) (stream-lazy strm))))))
         ^^^^^^^^^^^^
 
Immediate construction of the stream-pare does not consume more memory than the preparation of a promise, saves two cycles in procedure stream-force and does not force anything that should not yet be forced. I checked this with the unit-test. In my own streams-library, the equivalent of the above stream-cons passes all leak-tests (even the times3 test in a Scheme implementation (not to be mentioned here) that is rather susceptible to leaks in procedure stream-force)
 
Jos Koot

((((lambda(x)((((((x x)x)x)x)x)x))
   (lambda(x)(lambda(y)(x(x y)))))
  (lambda(x)(write x)x))
 'greeting)