Remove contrib.alias
I don't see why you'd put this in the standard library. I guess it could be useful for when you're maintaining a library and you want to change the name of a function or macro but keep the old name around for a while so people's code doesn't break immediately. But that's a pretty limited purpose.
This commit is contained in:
parent
7755778123
commit
d980a4a8ee
@ -1,60 +0,0 @@
|
|||||||
============
|
|
||||||
Alias macros
|
|
||||||
============
|
|
||||||
|
|
||||||
.. versionadded:: 0.12
|
|
||||||
|
|
||||||
The alias macro module provides the ``(defn-alias)`` and
|
|
||||||
``(defmacro-alias)``, that were in Hy core previously.
|
|
||||||
|
|
||||||
|
|
||||||
Macros
|
|
||||||
======
|
|
||||||
|
|
||||||
|
|
||||||
.. _defn-alias:
|
|
||||||
|
|
||||||
defn-alias
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
The ``defn-alias`` macro is much like ``defn``,
|
|
||||||
with the distinction 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``
|
|
||||||
is no different from ``defn``.
|
|
||||||
|
|
||||||
.. code-block:: clj
|
|
||||||
|
|
||||||
=> (defn-alias [main-name alias] []
|
|
||||||
... (print "Hello!"))
|
|
||||||
=> (main-name)
|
|
||||||
"Hello!"
|
|
||||||
=> (alias)
|
|
||||||
"Hello!"
|
|
||||||
|
|
||||||
|
|
||||||
.. _defmacro-alias:
|
|
||||||
|
|
||||||
defmacro-alias
|
|
||||||
--------------
|
|
||||||
|
|
||||||
``defmacro-alias`` is used to define macros with multiple names
|
|
||||||
(aliases). The general format is ``(defmacro-alias [names] [parameters]
|
|
||||||
expr)``. It creates multiple macros with the same parameter list and
|
|
||||||
body, under the specified list of names.
|
|
||||||
|
|
||||||
The following example defines two macros, both of which allow the user
|
|
||||||
to write code in infix notation.
|
|
||||||
|
|
||||||
.. code-block:: clj
|
|
||||||
|
|
||||||
=> (defmacro-alias [infix infi] [code]
|
|
||||||
... (quasiquote (
|
|
||||||
... (unquote (get code 1))
|
|
||||||
... (unquote (get code 0))
|
|
||||||
... (unquote (get code 2)))))
|
|
||||||
|
|
||||||
=> (infix (1 + 1))
|
|
||||||
2
|
|
||||||
=> (infi (1 + 1))
|
|
||||||
2
|
|
@ -7,7 +7,6 @@ Contents:
|
|||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 3
|
:maxdepth: 3
|
||||||
|
|
||||||
alias
|
|
||||||
anaphoric
|
anaphoric
|
||||||
flow
|
flow
|
||||||
loop
|
loop
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
;; Copyright (c) 2014, 2015 Gergely Nagy
|
|
||||||
;; Copyright (c) 2014, 2015 Paul Tagliamonte <paultag@debian.org>
|
|
||||||
|
|
||||||
;; Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
;; copy of this software and associated documentation files (the "Software"),
|
|
||||||
;; to deal in the Software without restriction, including without limitation
|
|
||||||
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
;; and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
;; Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
;; The above copyright notice and this permission notice shall be included in
|
|
||||||
;; all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
;; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
;; DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
(defmacro defmacro-alias [names lambda-list &rest body]
|
|
||||||
"define one macro with several names"
|
|
||||||
(setv ret `(do))
|
|
||||||
(for* [name names]
|
|
||||||
(.append ret
|
|
||||||
`(defmacro ~name ~lambda-list ~@body)))
|
|
||||||
ret)
|
|
||||||
|
|
||||||
|
|
||||||
(defmacro defn-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))
|
|
@ -1,8 +0,0 @@
|
|||||||
(require [hy.contrib.alias [defn-alias]])
|
|
||||||
|
|
||||||
(defn test-defn-alias []
|
|
||||||
(defn-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)))
|
|
Loading…
x
Reference in New Issue
Block a user