Merge branch 'master' into pr/461

Conflicts:
	tests/native_tests/native_macros.hy
This commit is contained in:
Nicolas Dandrimont 2014-01-23 21:57:17 +01:00
commit b99af411c8
6 changed files with 50 additions and 4 deletions

View File

@ -37,3 +37,4 @@
* Vasudev Kamath <kamathvasudev@gmail.com>
* Yuval Langer <yuval.langer@gmail.com>
* Fatih Kadir Akın <fka@fatihak.in>
* Jack Hooper <contact.jhooper@gmail.com>

View File

@ -352,6 +352,8 @@ below:
Meow
.. _defn:
defn / defun
------------
@ -422,6 +424,29 @@ Parameters may have following keywords in front of them:
=> (zig-zag-sum 1 2 3 4 5 6)
-3
.. _defn-alias / defun-alias:
defn-alias / defun-alias
------------------------
.. versionadded:: 0.9.13
The `defn-alias` and `defun-alias` macros are much like `defn`_ above,
with the difference that instead of defining a function with a single
name, these can also define aliases. Other than taking a list of
symbols for function names as the first parameter, `defn-alias` and
`defun-alias` have no other differences compared to `defn` and
`defun`.
.. code-block:: clj
=> (defn-alias [main-name alias] []
... (print "Hello!"))
=> (main-name)
"Hello!"
=> (alias)
"Hello!"
.. _defmacro:
defmacro

View File

@ -20,7 +20,7 @@ Command line options
.. cmdoption:: --spy
Print equivalent Hy code before executing. For example::
Print equivalent Python code before executing. For example::
=> (defn salutationsnm [name] (print (+ "Hy " name "!")))
def salutationsnm(name):

View File

@ -363,7 +363,7 @@ In hy, you could do these like:
(list-comp
(, x y)
(x (range 9)
(x (range 8)
y "ABCDEFGH"))
; [(0, 'A'), (0, 'B'), (0, 'C'), (0, 'D'), (0, 'E'), (0, 'F'), (0, 'G'), (0, 'H'),
@ -373,8 +373,7 @@ In hy, you could do these like:
; (4, 'A'), (4, 'B'), (4, 'C'), (4, 'D'), (4, 'E'), (4, 'F'), (4, 'G'), (4, 'H'),
; (5, 'A'), (5, 'B'), (5, 'C'), (5, 'D'), (5, 'E'), (5, 'F'), (5, 'G'), (5, 'H'),
; (6, 'A'), (6, 'B'), (6, 'C'), (6, 'D'), (6, 'E'), (6, 'F'), (6, 'G'), (6, 'H'),
; (7, 'A'), (7, 'B'), (7, 'C'), (7, 'D'), (7, 'E'), (7, 'F'), (7, 'G'), (7, 'H'),
; (8, 'A'), (8, 'B'), (8, 'C'), (8, 'D'), (8, 'E'), (8, 'F'), (8, 'G'), (8, 'H')]
; (7, 'A'), (7, 'B'), (7, 'C'), (7, 'D'), (7, 'E'), (7, 'F'), (7, 'G'), (7, 'H')]
Python has support for various fancy argument and keyword arguments.

View File

@ -188,3 +188,14 @@
(setv -args (cdr (car -args))))
`(apply ~-fun [~@-args] (dict (sum ~-okwargs [])))))
(defmacro-alias [defn-alias defun-alias] [names lambda-list &rest body]
"define one function with several names"
(let [[main (first names)]
[aliases (rest names)]]
(setv ret `(do (defn ~main ~lambda-list ~@body)))
(for* [name aliases]
(.append ret
`(setv ~name ~main)))
ret))

View File

@ -177,6 +177,7 @@
(assert (in ":res_" s2))
(assert (not (= s1 s2))))
(defn test-if-not []
(assert (= (if-not True :yes :no)
:no))
@ -185,3 +186,12 @@
(assert (nil? (if-not True :yes)))
(assert (= (if-not False :yes)
:yes)))
(defn test-defn-alias []
(defn-alias [tda-main tda-a1 tda-a2] [] :bazinga)
(defun-alias [tda-main tda-a1 tda-a2] [] :bazinga)
(assert (= (tda-main) :bazinga))
(assert (= (tda-a1) :bazinga))
(assert (= (tda-a2) :bazinga))
(assert (= tda-main tda-a1 tda-a2)))