fork download
  1. (define-syntax lazy-cons
  2. (syntax-rules ()
  3. ((_ head tail) (cons (delay head) (delay tail)))))
  4.  
  5. (define (lazy-head ll)
  6. (force (car ll)))
  7.  
  8. (define (lazy-tail ll)
  9. (force (cdr ll)))
  10.  
  11. (define-syntax lazy-list
  12. (syntax-rules ()
  13. ((_ x) (lazy-cons x '()))
  14. ((_ x . xs) (lazy-cons x (lazy-list . xs)))))
  15.  
  16. ;;; ----------------------------------------------------------------
  17.  
  18. (define ll (lazy-list (print 1) (print 2) (print 3)))
  19.  
  20. (lazy-head (lazy-tail ll))
Success #stdin #stdout 0.01s 8012KB
stdin
Standard input is empty
stdout
2