mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core: update doc of cond
This commit is contained in:
parent
bbb7920332
commit
357d28a167
@ -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))
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user