Merge branch 'better-macroexpand' of https://github.com/sbp/hy into sbp-better-macroexpand
Conflicts: hy/core/language.hy tests/native_tests/language.hy
This commit is contained in:
commit
88451bbeaa
@ -222,6 +222,33 @@ Contrast with :ref:`iterable?-fn`.
|
|||||||
|
|
||||||
.. _neg?-fn:
|
.. _neg?-fn:
|
||||||
|
|
||||||
|
macroexpand
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Usage: ``(macroexpand form)``
|
||||||
|
|
||||||
|
Returns the full macro expansion of form.
|
||||||
|
|
||||||
|
.. code-block:: clojure
|
||||||
|
|
||||||
|
=> (macroexpand '(-> (a b) (x y)))
|
||||||
|
(u'x' (u'a' u'b') u'y')
|
||||||
|
|
||||||
|
=> (macroexpand '(-> (a b) (-> (c d) (e f))))
|
||||||
|
(u'e' (u'c' (u'a' u'b') u'd') u'f')
|
||||||
|
|
||||||
|
macroexpand-1
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Usage: ``(macroexpand-1 form)``
|
||||||
|
|
||||||
|
Returns the single step macro expansion of form.
|
||||||
|
|
||||||
|
.. code-block:: clojure
|
||||||
|
|
||||||
|
=> (macroexpand-1 '(-> (a b) (-> (c d) (e f))))
|
||||||
|
(u'_>' (u'a' u'b') (u'c' u'd') (u'e' u'f'))
|
||||||
|
|
||||||
neg?
|
neg?
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -151,6 +151,24 @@
|
|||||||
(try (= x (iter x))
|
(try (= x (iter x))
|
||||||
(catch [TypeError] false)))
|
(catch [TypeError] false)))
|
||||||
|
|
||||||
|
(defn macroexpand [form]
|
||||||
|
"Return the full macro expansion of form"
|
||||||
|
(import inspect)
|
||||||
|
(import hy.macros)
|
||||||
|
|
||||||
|
(setv f (get (get (.stack inspect) 1) 0))
|
||||||
|
(setv name (get f.f_globals "__name__"))
|
||||||
|
(hy.macros.macroexpand form name))
|
||||||
|
|
||||||
|
(defn macroexpand-1 [form]
|
||||||
|
"Return the single step macro expansion of form"
|
||||||
|
(import inspect)
|
||||||
|
(import hy.macros)
|
||||||
|
|
||||||
|
(setv f (get (get (.stack inspect) 1) 0))
|
||||||
|
(setv name (get f.f_globals "__name__"))
|
||||||
|
(hy.macros.macroexpand-1 form name))
|
||||||
|
|
||||||
(defn neg? [n]
|
(defn neg? [n]
|
||||||
"Return true if n is < 0"
|
"Return true if n is < 0"
|
||||||
(_numeric-check n)
|
(_numeric-check n)
|
||||||
@ -254,8 +272,9 @@
|
|||||||
(_numeric_check n)
|
(_numeric_check n)
|
||||||
(= n 0))
|
(= n 0))
|
||||||
|
|
||||||
(def *exports* '[cycle dec distinct drop drop-while empty? even? filter flatten
|
(def *exports* '[cycle dec distinct drop drop-while empty? even? filter
|
||||||
float? gensym
|
flatten float? gensym inc instance? integer integer?
|
||||||
inc instance? integer integer? iterable? iterate iterator? neg?
|
iterable? iterate iterator? macroexpand macroexpand-1
|
||||||
nil? none? nth numeric? odd? pos? remove repeat repeatedly second
|
neg? nil? none? nth numeric? odd? pos? remove repeat
|
||||||
string string? take take-nth take-while zero?])
|
repeatedly second string string? take take-nth
|
||||||
|
take-while zero?])
|
||||||
|
@ -823,10 +823,12 @@
|
|||||||
(.append y x))
|
(.append y x))
|
||||||
(assert (= y [5])))
|
(assert (= y [5])))
|
||||||
|
|
||||||
|
|
||||||
(defn test-empty-list []
|
(defn test-empty-list []
|
||||||
"Evaluate an empty list to a []"
|
"Evaluate an empty list to a []"
|
||||||
(assert (= () [])))
|
(assert (= () [])))
|
||||||
|
|
||||||
|
|
||||||
(defn test-string []
|
(defn test-string []
|
||||||
(assert (string? (string "a")))
|
(assert (string? (string "a")))
|
||||||
(assert (string? (string 1)))
|
(assert (string? (string 1)))
|
||||||
@ -846,3 +848,17 @@
|
|||||||
(assert (= test [0 1 2 3]))
|
(assert (= test [0 1 2 3]))
|
||||||
(del (get test 2))
|
(del (get test 2))
|
||||||
(assert (= test [0 1 3])))
|
(assert (= test [0 1 3])))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-macroexpand []
|
||||||
|
"Test macroexpand on ->"
|
||||||
|
(assert (= (macroexpand '(-> (a b) (x y)))
|
||||||
|
'(x (a b) y)))
|
||||||
|
(assert (= (macroexpand '(-> (a b) (-> (c d) (e f))))
|
||||||
|
'(e (c (a b) d) f))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-macroexpand-1 []
|
||||||
|
"Test macroexpand-1 on ->"
|
||||||
|
(assert (= (macroexpand-1 '(-> (a b) (-> (c d) (e f))))
|
||||||
|
'(-> (a b) (c d) (e f)))))
|
||||||
|
Loading…
Reference in New Issue
Block a user