File: stream.sch

package info (click to toggle)
sdc 1.0.8beta-8
  • links: PTS
  • area: contrib
  • in suites: slink
  • size: 1,400 kB
  • ctags: 874
  • sloc: lisp: 8,120; ansic: 967; makefile: 671; perl: 136; sh: 50
file content (17 lines) | stat: -rw-r--r-- 325 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

(define-macro (cons-stream hd tl)
  `(cons ,hd (lambda () ,tl)))

(define-macro (tail-macro stream)
  `(let ((v (cdr ,stream)))
     (if (procedure? v)
	 (let ((nv (v)))
	   (set-cdr! ,stream nv)
	   nv)
	 v)))

(define-macro (stream->list-macro s)
  `(let loop ((r ,s))
     (if (stream-empty? r)
	 ,s
	 (loop (tail r)))))