words.scm 406 B

12345678910111213141516
  1. (define (whitespace? char)
  2. (or (char=? char #\space)
  3. (char=? char #\newline)
  4. (char=? char #\return)
  5. (char=? char #\tab)))
  6. (define (words)
  7. (let loop ((word '()))
  8. (let ((char (read-char)))
  9. (cond ((eof-object? char) '())
  10. ((whitespace? char)
  11. (if (null? word)
  12. (loop '())
  13. (cons (list->string (reverse word)) (loop '()))))
  14. (else (loop (cons char word)))))))