# Idiomatic way to implement tail -f in clojure

Disclaimer: This is just an educational task to learn how to program in clojure and switch brain to immutable state-way of developing (the provided snipped has some unused variables which I didn't clean up since they will be used soon and are easy to understand).

The current milestone: to implement a solution that reads all lines from a file, if reaching file end - sleep and reopen a file, then continue trying reading the file from the same place.

This code is ugly without doubts. What makes me worrying is that it uses recursion in an ugly manner to maintain state. I think my next iteration will be to try using atoms to maintain mutable state instead of recursions, but not sure yet if it will be any better.

The main function currently for testing purposes just reads 3 lines from the channel.

(ns log-multiline-join.tailer
(:use [clojure.core.async :only (>!! >! <!! thread chan timeout alt!)])
(:import [java.io RandomAccessFile])
(:gen-class))

(defn create-rac [filename]
(RandomAccessFile. filename "r"))

(defn read-lines [rac position out stop]
(.seek rac position)
(do
(>!! out line)
(recur rac (.getFilePointer rac) out stop))
(.getFilePointer rac)))

(let [rac (create-rac filename)
position (read-lines rac position out 2)]

(println "sleep")
(recur filename position out)))

(defn tailer [filename out]

(defn -main []
(let [out (chan)]