mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-11 06:47:37 +02:00
Added lazy library
This commit is contained in:
parent
fc6aadffd2
commit
2f89b7c825
1 changed files with 20 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
(import (scheme base)
|
||||
(scheme char)
|
||||
(scheme file)
|
||||
(scheme lazy)
|
||||
(scheme read)
|
||||
(scheme write)
|
||||
(scheme eval)
|
||||
|
@ -340,6 +341,25 @@
|
|||
(assert:equal "Record type predicate (f)" (record? (cons 1 2)) #f)
|
||||
;; END records
|
||||
|
||||
;; Lazy evaluation
|
||||
(assert:equal "Basic lazy" (force (delay (+ 1 2))) 3)
|
||||
(assert:equal "Lazy test #2"
|
||||
(let ((p (delay (+ 1 2))))
|
||||
(list (force p) (force p)))
|
||||
'(3 3))
|
||||
((lambda ()
|
||||
(define integers
|
||||
(letrec ((next
|
||||
(lambda (n)
|
||||
(delay (cons n (next (+ n 1)))))))
|
||||
(next 0)))
|
||||
(define head
|
||||
(lambda (stream) (car (force stream))))
|
||||
(define tail
|
||||
(lambda (stream) (cdr (force stream))))
|
||||
(assert:equal "Lazy #3" (head (tail (tail integers))) 2)))
|
||||
|
||||
|
||||
; TODO: use display, output without surrounding quotes
|
||||
(write (list *num-passed* " tests passed with no errors"))
|
||||
;;
|
||||
|
|
Loading…
Add table
Reference in a new issue