wordcount.scm 791 B

123456789101112131415161718192021222324252627
  1. ;; import lists/insertion-sort.scm files/words.scm files/count.scm
  2. (define (list->string chrs)
  3. (let ((l (length chrs)))
  4. (let ((s (make-string l #\?)))
  5. (let loop ((i 0) (chrs chrs))
  6. (if (null? chrs)
  7. s
  8. (begin
  9. (string-set! s i (car chrs))
  10. (loop (+ i 1) (cdr chrs))))))))
  11. (include "test/supporting/insertion-sort.scm")
  12. (include "test/supporting/words.scm")
  13. (include "test/supporting/count.scm")
  14. (define file "test/data/alice.txt")
  15. (define (write-line x) (begin (display x) (newline)))
  16. (define (call-with-input-file f p)
  17. (p (open-input-port f)))
  18. (define (write-line x) (begin (display x) (newline)))
  19. (define main
  20. (for-each write-line
  21. (sort-by (comparing < cdr)
  22. (call-with-input-file file count-words))))