Adding a simple `identity' function
* hy/core/language.hy: Adding a simple `identity` function that returns the argument supplied to it * docs/language/core.rst: Updated docs with identity function
This commit is contained in:
parent
e71631f48f
commit
10f1f24a18
@ -137,6 +137,24 @@ Raises ``TypeError`` if ``(not (numeric? x))``.
|
|||||||
True
|
True
|
||||||
|
|
||||||
|
|
||||||
|
.. _identity-fn:
|
||||||
|
|
||||||
|
identity
|
||||||
|
--------
|
||||||
|
|
||||||
|
Usage: ``(identity x)``
|
||||||
|
|
||||||
|
Returns argument supplied to the function
|
||||||
|
|
||||||
|
.. code-block:: clojure
|
||||||
|
|
||||||
|
=> (identity 4)
|
||||||
|
4
|
||||||
|
|
||||||
|
=> (list (map identity [1 2 3 4]))
|
||||||
|
[1 2 3 4]
|
||||||
|
|
||||||
|
|
||||||
.. _inc-fn:
|
.. _inc-fn:
|
||||||
|
|
||||||
inc
|
inc
|
||||||
|
@ -157,6 +157,10 @@
|
|||||||
"Return first item from `coll`"
|
"Return first item from `coll`"
|
||||||
(get coll 0))
|
(get coll 0))
|
||||||
|
|
||||||
|
(defn identity [x]
|
||||||
|
"Returns the argument unchanged"
|
||||||
|
x)
|
||||||
|
|
||||||
(defn inc [n]
|
(defn inc [n]
|
||||||
"Increment n by 1"
|
"Increment n by 1"
|
||||||
(_numeric-check n)
|
(_numeric-check n)
|
||||||
@ -310,10 +314,9 @@
|
|||||||
(_numeric_check n)
|
(_numeric_check n)
|
||||||
(= n 0))
|
(= n 0))
|
||||||
|
|
||||||
(def *exports* '[calling-module-name coll? cycle dec distinct
|
(def *exports* '[calling-module-name coll? cycle dec distinct disassemble
|
||||||
disassemble drop drop-while empty? even? filter flatten
|
drop drop-while empty? even? first filter flatten float?
|
||||||
float? gensym inc instance? integer integer? iterable?
|
gensym identity inc instance? integer integer? iterable?
|
||||||
iterate iterator? macroexpand macroexpand-1 neg? nil?
|
iterate iterator? macroexpand macroexpand-1 neg? nil?
|
||||||
none? nth numeric? odd? pos? remove repeat repeatedly
|
none? nth numeric? odd? pos? remove repeat repeatedly
|
||||||
second string string? take take-nth take-while zero?
|
rest second string string? take take-nth take-while zero?])
|
||||||
first rest])
|
|
||||||
|
@ -181,6 +181,12 @@
|
|||||||
(assert (not (= s2 s3)))
|
(assert (not (= s2 s3)))
|
||||||
(assert (not (= (str s2) (str s3)))))
|
(assert (not (= (str s2) (str s3)))))
|
||||||
|
|
||||||
|
(defn test-identity []
|
||||||
|
"NATIVE: testing the identity function"
|
||||||
|
(assert (= 4 (identity 4)))
|
||||||
|
(assert (= "hy" (identity "hy")))
|
||||||
|
(assert (= [1 2] (identity [1 2]))))
|
||||||
|
|
||||||
(defn test-inc []
|
(defn test-inc []
|
||||||
"NATIVE: testing the inc function"
|
"NATIVE: testing the inc function"
|
||||||
(assert-equal 3 (inc 2))
|
(assert-equal 3 (inc 2))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user