Debian Codegraph @

benchmarks.larceny/src/wc.scm

raw
1 ;;; WC -- One of the Kernighan and Van Wyk benchmarks.
2
3 (define inport #f)
4
5 (define nl #f)
6 (define nw #f)
7 (define nc #f)
8 (define inword #f)
9
10 (define (wcport port)
11 (let ((x (read-char port)))
12 (if (eof-object? x)
13 (begin
14 (list nl nw nc))
15 (begin
16 (set! nc (+ nc 1))
17 (if (char=? x #\newline)
18 (set! nl (+ nl 1)))
19 (if (or (char=? x #\space)
20 (char=? x #\newline))
21 (set! inword #f)
22 (if (not inword)
23 (begin
24 (set! nw (+ nw 1))
25 (set! inword #t))))
26 (wcport port)))))
27
28 (define (go)
29 (set! inport (open-input-file "../../src/bib"))
30 (set! nl 0)
31 (set! nw 0)
32 (set! nc 0)
33 (set! inword #f)
34 (let ((result (wcport inport)))
35 (close-input-port inport)
36 result))
37
38 (define (main . args)
39 (run-benchmark
40 "wc"
41 wc-iters
42 (lambda (result) (equal? result '(31102 851820 4460056)))
43 (lambda () (lambda () (go)))))