1;;; TAIL -- One of the Kernighan and Van Wyk benchmarks.
2
3(define inport #f)
4(define outport #f)
5
6(define (readline port line-so-far)
7  (let ((x (read-char port)))
8    (cond ((eof-object? x)
9           x)
10          ((char=? x #\newline)
11           (list->string (reverse
12                          (cons x line-so-far))))
13          (#t (readline port (cons x line-so-far))))))
14
15(define (tail-r-aux port file-so-far)
16  (let ((x (readline port '())))
17    (if (eof-object? x)
18        (begin
19          (display file-so-far outport)
20          (close-output-port outport))
21        (tail-r-aux port (cons x file-so-far)))))
22
23(define (tail-r port)
24  (tail-r-aux port '()))
25
26(define (go)
27  (set! inport (open-input-file "../../src/bib"))
28  (set! outport (open-output-file "foo"))
29  (tail-r inport)
30  (close-input-port inport))
31
32(define (main . args)
33  (run-benchmark
34   "tail"
35   tail-iters
36   (lambda (result) #t)
37   (lambda () (lambda () (go)))))
38