2014-01-26 03:53:44 +01:00
|
|
|
(import [hy.contrib.walk [*]])
|
|
|
|
|
|
|
|
(def walk-form '(print {"foo" "bar"
|
|
|
|
"array" [1 2 3 [4]]
|
|
|
|
"something" (+ 1 2 3 4)
|
2014-02-01 18:36:57 +01:00
|
|
|
"cons!" (cons 1 2)
|
2014-01-26 03:53:44 +01:00
|
|
|
"quoted?" '(foo)}))
|
|
|
|
|
|
|
|
(defn collector [acc x]
|
|
|
|
(.append acc x)
|
|
|
|
nil)
|
|
|
|
|
|
|
|
(defn test-walk-identity []
|
|
|
|
(assert (= (walk identity identity walk-form)
|
|
|
|
walk-form)))
|
|
|
|
|
|
|
|
(defn test-walk []
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [acc '()]
|
2014-01-26 03:53:44 +01:00
|
|
|
(assert (= (walk (partial collector acc) identity walk-form)
|
|
|
|
[nil nil]))
|
|
|
|
(assert (= acc walk-form)))
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [acc []]
|
2014-01-26 03:53:44 +01:00
|
|
|
(assert (= (walk identity (partial collector acc) walk-form)
|
|
|
|
nil))
|
|
|
|
(assert (= acc [walk-form]))))
|
2014-01-26 03:59:47 +01:00
|
|
|
|
2015-07-15 16:59:49 +02:00
|
|
|
(defn test-walk-iterators []
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [acc []]
|
2015-07-15 16:59:49 +02:00
|
|
|
(assert (= (walk (fn [x] (* 2 x)) (fn [x] x)
|
|
|
|
(drop 1 [1 [2 [3 [4]]]]))
|
|
|
|
[[2 [3 [4]] 2 [3 [4]]]]))))
|
|
|
|
|
2014-01-26 03:59:47 +01:00
|
|
|
(defn test-macroexpand-all []
|
2015-08-13 16:37:56 +02:00
|
|
|
(assert (= (macroexpand-all '(with [a 1 b 2 c 3] (for [d c] foo)))
|
|
|
|
'(with* [a 1] (with* [b 2] (with* [c 3] (do (for* [d c] (do foo)))))))))
|