From c6410b70505b7233dd6b1a1857fa62b1cc70247e Mon Sep 17 00:00:00 2001 From: Tuukka Turto Date: Mon, 22 Jul 2013 23:59:21 +0300 Subject: [PATCH] cond documentation --- docs/language/api.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/language/api.rst b/docs/language/api.rst index 420a05d..9acaeb1 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -140,6 +140,32 @@ the user enters `k`. cond ---- +`cond` macro can be used to build nested if-statements. + +The following example shows the relationship between the macro and the expanded +code: + +.. code-block:: clj + + (cond (condition-1 result-1) + (condition-2 result-2)) + + (if condition-1 result-1 + (if condition-2 result-2)) + +As shown below only the first matching result block is executed. + +.. code-block:: clj + + => (defn check-value [value] + ... (cond ((< value 5) (print "value is smaller than 5")) + ... ((= value 5) (print "value is equal to 5")) + ... ((> value 5) (print "value is greater than 5")) + ... (True (print "value is something that it should not be")))) + + => (check-value 6) + value is greater than 5 + continue --------