Merge branch 'master' of github.com:hylang/hy into paultag/bugfix/python3.4

This commit is contained in:
Paul Tagliamonte 2014-01-01 18:58:39 -05:00
commit d22a152134
3 changed files with 70 additions and 8 deletions

View File

@ -222,6 +222,33 @@ Contrast with :ref:`iterable?-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?
----

View File

@ -151,6 +151,24 @@
(try (= x (iter x))
(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]
"Return true if n is < 0"
(_numeric-check n)
@ -254,8 +272,9 @@
(_numeric_check n)
(= n 0))
(def *exports* '[cycle dec distinct drop drop-while empty? even? filter flatten
float? gensym
inc instance? integer integer? iterable? iterate iterator? neg?
nil? none? nth numeric? odd? pos? remove repeat repeatedly second
string string? take take-nth take-while zero?])
(def *exports* '[cycle dec distinct drop drop-while empty? even? filter
flatten float? gensym inc instance? integer integer?
iterable? iterate iterator? macroexpand macroexpand-1
neg? nil? none? nth numeric? odd? pos? remove repeat
repeatedly second string string? take take-nth
take-while zero?])

View File

@ -817,16 +817,18 @@
(defn test-continue-continuation []
"NATIVE: test checking if continue actually continues"
(setv y [])
(for [x (range 10)]
(if (!= x 5)
(continue))
(for [x (range 10)]
(if (!= x 5)
(continue))
(.append y x))
(assert (= y [5])))
(defn test-empty-list []
"Evaluate an empty list to a []"
(assert (= () [])))
(defn test-string []
(assert (string? (string "a")))
(assert (string? (string 1)))
@ -846,3 +848,17 @@
(assert (= test [0 1 2 3]))
(del (get test 2))
(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)))))