Added macroexpand-1
This commit is contained in:
parent
033198a90e
commit
defccc6853
@ -227,13 +227,28 @@ macroexpand
|
|||||||
|
|
||||||
Usage: ``(macroexpand form)``
|
Usage: ``(macroexpand form)``
|
||||||
|
|
||||||
Returns the macro expansion of form.
|
Returns the full macro expansion of form.
|
||||||
|
|
||||||
.. code-block:: clojure
|
.. code-block:: clojure
|
||||||
|
|
||||||
=> (macroexpand '(-> (a b) (x y)))
|
=> (macroexpand '(-> (a b) (x y)))
|
||||||
(u'x' (u'a' u'b') u'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?
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -120,10 +120,15 @@
|
|||||||
(catch [TypeError] false)))
|
(catch [TypeError] false)))
|
||||||
|
|
||||||
(defn macroexpand [form]
|
(defn macroexpand [form]
|
||||||
"Return the macro expansion of form"
|
"Return the full macro expansion of form"
|
||||||
(import hy.macros)
|
(import hy.macros)
|
||||||
(hy.macros.macroexpand form --name--))
|
(hy.macros.macroexpand form --name--))
|
||||||
|
|
||||||
|
(defn macroexpand-1 [form]
|
||||||
|
"Return the single step macro expansion of form"
|
||||||
|
(import hy.macros)
|
||||||
|
(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)
|
||||||
@ -219,6 +224,7 @@
|
|||||||
|
|
||||||
(def *exports* ["cycle" "dec" "distinct" "drop" "drop_while" "empty?" "even?"
|
(def *exports* ["cycle" "dec" "distinct" "drop" "drop_while" "empty?" "even?"
|
||||||
"filter" "float?" "inc" "instance?" "integer?" "iterable?"
|
"filter" "float?" "inc" "instance?" "integer?" "iterable?"
|
||||||
"iterate" "iterator?" "macroexpand" "neg?" "none?" "nth"
|
"iterate" "iterator?" "macroexpand" "macroexpand_1" "neg?"
|
||||||
"numeric?" "odd?" "pos?" "remove" "repeat" "repeatedly"
|
"none?" "nth" "numeric?" "odd?" "pos?" "remove" "repeat"
|
||||||
"second" "string?" "take" "take_nth" "take_while" "zero?"])
|
"repeatedly" "second" "string?" "take" "take_nth" "take_while"
|
||||||
|
"zero?"])
|
||||||
|
@ -782,6 +782,14 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn test-macroexpand []
|
(defn test-macroexpand []
|
||||||
"Test macroexpand on ->"
|
"Test macroexpand on ->"
|
||||||
(assert (= (macroexpand '(-> (a b) (x y)))
|
(assert (= (macroexpand '(-> (a b) (x y)))
|
||||||
'(x (a b) 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