markov-algorithm-cli.lisp 683 B

1234567891011121314151617181920
  1. (defpackage #:markov-algorithm/cli
  2. (:use #:cl)
  3. (:export #:main))
  4. (in-package #:markov-algorithm/cli)
  5. (defun main (args)
  6. "CLI interface to Markov algorithms"
  7. (loop with file = (first args)
  8. with scheme = (with-open-file (in file :direction :input)
  9. (read in))
  10. with compiled-scheme = (markov-algorithm:compile-markov-algorithm scheme)
  11. for line = (read-line nil nil)
  12. while line
  13. for transformed-line = (funcall compiled-scheme line)
  14. do (if (null transformed-line)
  15. (error "Iteration limit is reached.")
  16. (write-line (funcall compiled-scheme line)))
  17. finally (return t)))