Files
  • main.clj
  • target
main.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(require '[clojure.java.io :as io])

(set! *warn-on-reflection* true)
;;(set! *print-meta* true)

(def file (io/file "hej"))
(.getName file) ;; reflection warning

(def generated-fn `(fn [~'file] (.getName ~'file)))

(eval generated-fn) ;; reflection warning 

;;(def generated-fn2 `(fn [~(with-meta 'file {:tag java.io.File})] (.getName ~'file)))
;;(prn generated-fn2) ;; (clojure.core/fn [^java.io.File file] (.getName file))
;;(eval generated-fn2) ;; reflection warning, but why?

;;(clojure.core/fn [^java.io.File file] (.getName file)) ;; no reflection warning

#_(def generated-fn2
  (let [file (gensym)]
    `(fn [~(with-meta file {:tag 'java.io.File})]
       [email protected](for [_ (range 3)]
           `(.getName ~file)))))

;;(eval generated-fn2) 
Clojure 1.8.0 Java HotSpot(TM) 64-Bit Server VM 1.8.0_91-b14