use-syntax ice-9 syncase define make-source sequence eof let xs if not

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(use-syntax (ice-9 syncase))
(define (make-source sequence . eof)
(let ((xs (if (not (null? eof))
eof
(list #f))))
(cond ((string? sequence) (append (string->list sequence) (list xs)))
((vector? sequence) (append (vector->list sequence) (list xs)))
(else (append sequence (list xs))))))
(define-syntax peek
(syntax-rules ()
((_ src) (if (and (= (length src) 1) (list? (car src)))
(caar src)
(car src)))))
(define-syntax next
(syntax-rules ()
((_ src) (let ((char (car src)))
(if (and (= (length src) 1) (list? (car src)))
(car char)
(begin (set! src (cdr src))
char))))))