Created
November 4, 2015 19:21
-
-
Save rmnssnvsk/c78d514a0a191851cdd2 to your computer and use it in GitHub Desktop.
Реализация бесконечного списка чисел Фиббоначи
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax lazy-cons | |
(syntax-rules () | |
((_ a b) (cons a (delay b))))) | |
(define (lazy-cdr ls) (force (cdr ls))) | |
(define lazy-car car) | |
(define (lazy-ref ls n) | |
(if (zero? n) | |
(lazy-car ls) | |
(lazy-ref (lazy-cdr ls) (- n 1)))) | |
(define (fib-gen a b) | |
(lazy-cons a (fib-gen b (+ a b)))) | |
(define (lazy-fib n) | |
(lazy-ref (fib-gen 0 1) n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment