Documentation of the &key modifier in (defn)
This commit is contained in:
parent
2b49403507
commit
b3a85801bd
@ -400,7 +400,7 @@ below:
|
|||||||
.. _defn:
|
.. _defn:
|
||||||
|
|
||||||
defn
|
defn
|
||||||
------------
|
----
|
||||||
|
|
||||||
``defn`` macro is used to define functions. It takes 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*,
|
||||||
@ -430,7 +430,26 @@ Parameters may have the following keywords in front of them:
|
|||||||
101.0
|
101.0
|
||||||
|
|
||||||
&key
|
&key
|
||||||
|
Parameter is a dict of keyword arguments. The keys of the dict
|
||||||
|
specify the parameter names and the values give the default values
|
||||||
|
of the parameters.
|
||||||
|
|
||||||
|
.. code-block:: clj
|
||||||
|
|
||||||
|
=> (defn key-parameters [&key {"a" 1 "b" 2}]
|
||||||
|
... (print "a is" a "and b is" b))
|
||||||
|
=> (key-parameters :a 1 :b 2)
|
||||||
|
a is 1 and b is 2
|
||||||
|
=> (key-parameters :b 1 :a 2)
|
||||||
|
a is 2 and b is 1
|
||||||
|
|
||||||
|
The following declarations are equivalent:
|
||||||
|
|
||||||
|
.. code-block:: clj
|
||||||
|
|
||||||
|
(defn key-parameters [&key {"a" 1 "b" 2}])
|
||||||
|
|
||||||
|
(defn key-parameters [&optional [a 1] [b 2]])
|
||||||
|
|
||||||
&kwargs
|
&kwargs
|
||||||
Parameter will contain 0 or more keyword arguments.
|
Parameter will contain 0 or more keyword arguments.
|
||||||
|
Loading…
Reference in New Issue
Block a user