core: update doc of cond

This commit is contained in:
hellerve 2020-05-26 21:50:26 +02:00
parent bbb7920332
commit 357d28a167
2 changed files with 19 additions and 8 deletions

View File

@ -489,6 +489,17 @@ of those interfaces.")
(cadr xs)
(cond-internal (cddr xs)))))))
(doc cond "executes a block of code if a specified condition is true. Multiple
such blocks can be chained.
For example:
```
(cond
(< 10 1) (println \"Condition 1 is true\")
(> 10 1) (println \"Condition 2 is true\")
(println \"Else branch\"))
```")
(defmacro cond [:rest xs]
(cond-internal xs))

View File

@ -69,8 +69,8 @@ foo ; symbol
(defmodule <name> <definition1> <definition2> ...) ;; The main way to organize your program into smaller parts
```
### Conditional statements with 'cond'
The ```cond``` statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.
### Conditional statements with `cond`
The ```cond``` statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.
```(doc cond "this is the documentation for cond")```
@ -81,17 +81,17 @@ Usage:
(<condition_1>) (<code_1>) ;; code_1 gets executed if condition_1 is true
(<condition_2>) (<code_2>) ;; code_2 gets executed if condition_2 is true
(<code_3>) ;; code_3 gets executed if condition_1 and condition_2 are false
```
```
Here's an example about printing a statement depending on whether it is < or > 10:
```clojure
(cond
(< 10 1) (println "Don't print!")
(> 10 1) (println msg)
(println "Don't print!"))
```
(< 10 1) (println "Don't print!")
(> 10 1) (println msg)
(println "Don't print!"))
```
### Special Forms
The following forms can be used in Carp source code and will be compiled to C after type checking
and other static analysis. The first three of them are also available in dynamic functions.