2

there are a few related questions on SO but I just can't seem to figure this out. I've got a very simple test code:

(ns test
  (:gen-class)
  (:require [clojure.java.io :as io]))

(defn tail-file
  [path handler-func]
  (org.apache.commons.io.input.Tailer/create
     (io/file path)
     (proxy [org.apache.commons.io.input.TailerListenerAdapter] []
                   (handle [this line] (handler-func line)))))

(defn -main
  [& args]
  (tail-file "c:/tmp/test.txt" println)
  (read-line))

This results in:

Exception in thread "Thread-0" clojure.lang.ArityException: Wrong number of args (2) passed to: core/tail-file/fn--28

That's strange because tail-file takes two arguments ([path handler-func]).

Mate Varga
  • 3,144
  • 2
  • 14
  • 17

1 Answers1

4

You should omit this in handle definition, since it is declared implicitly as stated in the docs

Each method fn takes an additional implicit first arg, which is bound to 'this.

this should be explicitly set when using reify

Notice that the error message didnt say there was an error in tail-file, but in some function generated in tail-file: core/tail-file/fn--28, namely, fn--28.

Shlomi
  • 4,708
  • 1
  • 23
  • 32