floyd-library/test/test.scm

41 lines
1.2 KiB
Scheme

(import (scheme base)
(scheme write)
(list-error)
(floyd))
(define (circular-list first . rest)
(let ((head (list first)))
(let loop ((tail head) (rest rest))
(cond ((null? rest)
(set-cdr! tail head)
head)
(else
(set-cdr! tail (list (car rest)))
(loop (cdr tail) (cdr rest)))))))
(define (generator->list g)
(let loop ((xs '()))
(let ((x (g)))
(if (eof-object? x)
(reverse xs)
(loop (cons x xs))))))
(define-syntax show
(syntax-rules ()
((show expr)
(begin (write 'expr)
(write-string " => ")
(write expr)
(newline)))))
(show (generator->list (floyd-generator '((1 2 3 4) (a b c d) (x y z)))))
(show (generator->list (floyd-generator '((1 2 3 4) (a b c d) (x y z å)))))
(show (generator->list (floyd-generator '((1 2 3 4) (a b c d) ()))))
(show (generator->list (floyd-generator (list '(1 2 3 4)
(circular-list 'a 'b 'c)))))
(show (generator->list (floyd-generator (list (circular-list 1 2 3 4 5 6)
(circular-list 'a 'b)))))