(define-syntax lazy-cons
(syntax-rules ()
((_ head tail) (cons (delay head) (delay tail)))))
(define (lazy-head ll)
(force (car ll)))
(define (lazy-tail ll)
(force (cdr ll)))
(define-syntax lazy-list
(syntax-rules ()
((_ x) (lazy-cons x '()))
((_ x . xs) (lazy-cons x (lazy-list . xs)))))
;;; ----------------------------------------------------------------
(define (lazy-take n xs)
(cond ((<= n 0)
'())
((null? xs)
'())
(else
(lazy-cons (lazy-head xs) (lazy-take (- n 1) (lazy-tail xs))))))
(define (lazy-zip f xs ys)
(cond ((null? xs) '())
((null? ys) '())
(else (lazy-cons (f (lazy-head xs) (lazy-head ys))
(lazy-zip f (lazy-tail xs) (lazy-tail ys))))))
(define (force-list xs)
(if (null? xs)
'()
(cons (lazy-head xs) (force-list (lazy-tail xs)))))
;;; ----------------------------------------------------------------
(define fibs (lazy-cons 0 (lazy-cons 1 (lazy-zip + fibs (lazy-tail fibs)))))
(print (force-list (lazy-take 10 fibs)))
KGRlZmluZS1zeW50YXggbGF6eS1jb25zCiAgKHN5bnRheC1ydWxlcyAoKQogICAgKChfIGhlYWQgdGFpbCkgKGNvbnMgKGRlbGF5IGhlYWQpIChkZWxheSB0YWlsKSkpKSkKCihkZWZpbmUgKGxhenktaGVhZCBsbCkKICAoZm9yY2UgKGNhciBsbCkpKQoKKGRlZmluZSAobGF6eS10YWlsIGxsKQogIChmb3JjZSAoY2RyIGxsKSkpCgooZGVmaW5lLXN5bnRheCBsYXp5LWxpc3QKICAoc3ludGF4LXJ1bGVzICgpCiAgICAoKF8geCkgICAgICAobGF6eS1jb25zIHggJygpKSkKICAgICgoXyB4IC4geHMpIChsYXp5LWNvbnMgeCAobGF6eS1saXN0IC4geHMpKSkpKQoKOzs7IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KCihkZWZpbmUgKGxhenktdGFrZSBuIHhzKQogIChjb25kICgoPD0gbiAwKQogICAgICAgICAnKCkpCiAgICAgICAgKChudWxsPyB4cykKICAgICAgICAgJygpKQogICAgICAgIChlbHNlCiAgICAgICAgIChsYXp5LWNvbnMgKGxhenktaGVhZCB4cykgKGxhenktdGFrZSAoLSBuIDEpIChsYXp5LXRhaWwgeHMpKSkpKSkKCihkZWZpbmUgKGxhenktemlwIGYgeHMgeXMpCiAgKGNvbmQgKChudWxsPyB4cykgJygpKQogICAgICAgICgobnVsbD8geXMpICcoKSkKICAgICAgICAoZWxzZSAobGF6eS1jb25zIChmIChsYXp5LWhlYWQgeHMpIChsYXp5LWhlYWQgeXMpKQogICAgICAgICAgICAgICAgICAgICAgICAgKGxhenktemlwIGYgKGxhenktdGFpbCB4cykgKGxhenktdGFpbCB5cykpKSkpKQoKKGRlZmluZSAoZm9yY2UtbGlzdCB4cykKICAoaWYgKG51bGw/IHhzKQogICAgICAnKCkKICAgICAgKGNvbnMgKGxhenktaGVhZCB4cykgKGZvcmNlLWxpc3QgKGxhenktdGFpbCB4cykpKSkpCgo7OzsgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQoKKGRlZmluZSBmaWJzIChsYXp5LWNvbnMgMCAobGF6eS1jb25zIDEgKGxhenktemlwICsgZmlicyAobGF6eS10YWlsIGZpYnMpKSkpKQoKKHByaW50IChmb3JjZS1saXN0IChsYXp5LXRha2UgMTAgZmlicykpKQ==