remove defun in favor of defn
This commit is contained in:
parent
33e0b4b3db
commit
4cdfdfbafe
@ -378,10 +378,10 @@ below:
|
|||||||
|
|
||||||
.. _defn:
|
.. _defn:
|
||||||
|
|
||||||
defn / defun
|
defn
|
||||||
------------
|
------------
|
||||||
|
|
||||||
``defn`` and ``defun`` macros are used to define functions. They take three
|
``defn`` macro is used to define functions. It takes three
|
||||||
parameters: the *name* of the function to define, a vector of *parameters*,
|
parameters: the *name* of the function to define, a vector of *parameters*,
|
||||||
and the *body* of the function:
|
and the *body* of the function:
|
||||||
|
|
||||||
@ -488,18 +488,18 @@ Parameters may have the following keywords in front of them:
|
|||||||
|
|
||||||
Availability: Python 3.
|
Availability: Python 3.
|
||||||
|
|
||||||
.. _defn-alias / defun-alias:
|
.. _defn-alias:
|
||||||
|
|
||||||
defn-alias / defun-alias
|
defn-alias
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
.. versionadded:: 0.10.0
|
.. versionadded:: 0.10.0
|
||||||
|
|
||||||
The ``defn-alias`` and ``defun-alias`` macros are much like `defn`_,
|
The ``defn-alias`` and macro is much like `defn`_,
|
||||||
with the distinction that instead of defining a function with a single
|
with the distinction that instead of defining a function with a single
|
||||||
name, these can also define aliases. Other than taking a list of
|
name, these can also define aliases. Other than taking a list of
|
||||||
symbols for function names as the first parameter, ``defn-alias`` and
|
symbols for function names as the first parameter, ``defn-alias``
|
||||||
``defun-alias`` are no different from ``defn`` and ``defun``.
|
is no different from ``defn``.
|
||||||
|
|
||||||
.. code-block:: clj
|
.. code-block:: clj
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
;; DEALINGS IN THE SOFTWARE.
|
;; DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
(defun Botsbuildbots () (Botsbuildbots))
|
(defn Botsbuildbots () (Botsbuildbots))
|
||||||
|
|
||||||
(defmacro Botsbuildbots []
|
(defmacro Botsbuildbots []
|
||||||
"Build bots, repeatedly.^W^W^WPrint the AUTHORS, forever."
|
"Build bots, repeatedly.^W^W^WPrint the AUTHORS, forever."
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
(defmacro/g! loop [bindings &rest body]
|
(defmacro/g! loop [bindings &rest body]
|
||||||
;; Use inside functions like so:
|
;; Use inside functions like so:
|
||||||
;; (defun factorial [n]
|
;; (defn factorial [n]
|
||||||
;; (loop [[i n]
|
;; (loop [[i n]
|
||||||
;; [acc 1]]
|
;; [acc 1]]
|
||||||
;; (if (= i 0)
|
;; (if (= i 0)
|
||||||
|
@ -40,12 +40,12 @@
|
|||||||
ret)
|
ret)
|
||||||
|
|
||||||
|
|
||||||
(defmacro-alias [defn defun] [name lambda-list &rest body]
|
(defmacro defn [name lambda-list &rest body]
|
||||||
"define a function `name` with signature `lambda-list` and body `body`"
|
"define a function `name` with signature `lambda-list` and body `body`"
|
||||||
(if (not (= (type name) HySymbol))
|
(if (not (= (type name) HySymbol))
|
||||||
(macro-error name "defn/defun takes a name as first argument"))
|
(macro-error name "defn takes a name as first argument"))
|
||||||
(if (not (isinstance lambda-list HyList))
|
(if (not (isinstance lambda-list HyList))
|
||||||
(macro-error name "defn/defun takes a parameter list as second argument"))
|
(macro-error name "defn takes a parameter list as second argument"))
|
||||||
`(setv ~name (fn ~lambda-list ~@body)))
|
`(setv ~name (fn ~lambda-list ~@body)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@
|
|||||||
(sys.exit ~retval)))))
|
(sys.exit ~retval)))))
|
||||||
|
|
||||||
|
|
||||||
(defmacro-alias [defn-alias defun-alias] [names lambda-list &rest body]
|
(defmacro defn-alias [names lambda-list &rest body]
|
||||||
"define one function with several names"
|
"define one function with several names"
|
||||||
(let [[main (first names)]
|
(let [[main (first names)]
|
||||||
[aliases (rest names)]]
|
[aliases (rest names)]]
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
(setv *maintainer-line*
|
(setv *maintainer-line*
|
||||||
" -- Alexander Artemenko <svetlyak.40wt@gmail.com> Thu, 30 Sep 2014 13:06:09 +0400")
|
" -- Alexander Artemenko <svetlyak.40wt@gmail.com> Thu, 30 Sep 2014 13:06:09 +0400")
|
||||||
|
|
||||||
(defun read-lines-from-file [filename]
|
(defn read-lines-from-file [filename]
|
||||||
(let [[f (codecs.open filename "r" "utf-8")]]
|
(let [[f (codecs.open filename "r" "utf-8")]]
|
||||||
(fn [] (let [[line (.readline f) ]]
|
(fn [] (let [[line (.readline f) ]]
|
||||||
line))))
|
line))))
|
||||||
|
|
||||||
|
|
||||||
(defun get-version-number [line]
|
(defn get-version-number [line]
|
||||||
(let [[match (re.search r"Changes from.*(\d+\.\d+\.\d+)$" line)]]
|
(let [[match (re.search r"Changes from.*(\d+\.\d+\.\d+)$" line)]]
|
||||||
(if match
|
(if match
|
||||||
(let [[version (.group match (int 1))]
|
(let [[version (.group match (int 1))]
|
||||||
@ -26,7 +26,7 @@
|
|||||||
(.join "." (map str numbered)))))))
|
(.join "." (map str numbered)))))))
|
||||||
|
|
||||||
|
|
||||||
(defun read-version-content [reader]
|
(defn read-version-content [reader]
|
||||||
(setv line (reader))
|
(setv line (reader))
|
||||||
(setv content [])
|
(setv content [])
|
||||||
(while (and line (not (get-version-number line)))
|
(while (and line (not (get-version-number line)))
|
||||||
@ -35,12 +35,12 @@
|
|||||||
[content line])
|
[content line])
|
||||||
|
|
||||||
|
|
||||||
(defun read-versions-from-file [filename]
|
(defn read-versions-from-file [filename]
|
||||||
(let [[reader (read-lines-from-file filename)]]
|
(let [[reader (read-lines-from-file filename)]]
|
||||||
(read-versions-rec (reader)
|
(read-versions-rec (reader)
|
||||||
reader)))
|
reader)))
|
||||||
|
|
||||||
(defun read-versions-rec [line reader]
|
(defn read-versions-rec [line reader]
|
||||||
(if line
|
(if line
|
||||||
(let [[version (get-version-number line)]
|
(let [[version (get-version-number line)]
|
||||||
[[content next-line] (read-version-content reader)]]
|
[[content next-line] (read-version-content reader)]]
|
||||||
@ -50,7 +50,7 @@
|
|||||||
(read-versions-rec next-line reader)))
|
(read-versions-rec next-line reader)))
|
||||||
[]))
|
[]))
|
||||||
|
|
||||||
(defun format-deb-version [version]
|
(defn format-deb-version [version]
|
||||||
(setv result [(.format "hy ({}) unstable; urgency=low"
|
(setv result [(.format "hy ({}) unstable; urgency=low"
|
||||||
(get version "from"))])
|
(get version "from"))])
|
||||||
(for [line (get version "content")]
|
(for [line (get version "content")]
|
||||||
|
@ -227,7 +227,6 @@
|
|||||||
|
|
||||||
(defn test-defn-alias []
|
(defn test-defn-alias []
|
||||||
(defn-alias [tda-main tda-a1 tda-a2] [] :bazinga)
|
(defn-alias [tda-main tda-a1 tda-a2] [] :bazinga)
|
||||||
(defun-alias [tda-main tda-a1 tda-a2] [] :bazinga)
|
|
||||||
(assert (= (tda-main) :bazinga))
|
(assert (= (tda-main) :bazinga))
|
||||||
(assert (= (tda-a1) :bazinga))
|
(assert (= (tda-a1) :bazinga))
|
||||||
(assert (= (tda-a2) :bazinga))
|
(assert (= (tda-a2) :bazinga))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user