(use 'clojure.contrib.repl-utils)
(source ->)
(-> 20 (* 9) (/ 5) (+ 32))
(use 'clojure.inspector)
(inspect-tree '(-> 20 (* 9) (/ 5) (+ 32)))
(use 'clojure.walk)
(macroexpand-all '(-> 20 (* 9) (/ 5) (+ 32)))
(inspect-tree (macroexpand-all '(-> 20 (* 9) (/ 5) (+ 32))))
(macroexpand-1 '(-> 20 (* 9) (/ 5) (+ 32)))
(macroexpand-1 '(-> 20 (* 9) (/ 5) (+ 32)))
(macroexpand-1
'(->
(-> 20 (* 9))
(/ 5) (+ 32)))
(macroexpand-1
'(->
(->
(-> 20 (* 9))
(/ 5))
(+ 32)))
(macroexpand-1
'(+
(->
(-> 20 (* 9))
(/ 5))
32))
`(+
~(macroexpand-1 '
(->
(-> 20 (* 9))
(/ 5)))
32)
`(+
(/
~(macroexpand-1 '
(-> 20 (* 9)))
5)
32)
(+
(/
(* 20 9)
5)
32)
(defn slow-tree-transformer [fn tree]
(cond (not (seq? tree)) (fn tree)
(empty? tree) '()
:else (let [nxt (fn tree)]
(if (not (= nxt tree)) nxt
(let [nxt (fn (first tree))]
(if (= nxt (first tree))
(let [nxt (slow-tree-transformer fn (first tree))]
(if (= nxt (first tree))
(cons (first tree) (slow-tree-transformer fn (rest tree)))
(cons nxt (rest tree))))
(cons nxt (rest tree))))))))
(def f (fn[x] (slow-tree-transformer macroexpand-1 x)))
(defn iterate-to-stable [fn start]
(let [next (fn start)]
(if (= next start) (list start)
(cons start (iterate-to-stable fn next)))))
(use 'clojure.contrib.pprint)
(println "-----------------------------------")
(doall (map (fn [x] (pprint x) (println)) (iterate-to-stable f '(-> 20 (* 9) (/ 5) (+ 32)))))
(println "-----------------------------------")
No comments:
Post a Comment