Thun/docs/reference/cond.md

36 lines
852 B
Markdown

------------------------------------------------------------------------
## cond
Combinator
This combinator works like a case statement. It expects a single quote
on the stack that must contain zero or more condition quotes and a
default quote. Each condition quote should contain a quoted predicate
followed by the function expression to run if that predicate returns
`true`. If no predicates return `true` the default function runs.
[
[ [Predicate0] Function0 ]
[ [Predicate1] Function1 ]
...
[ [PredicateN] FunctionN ]
[Default]
]
cond
### Discussion
It works by rewriting into a chain of nested [ifte]{.title-ref}
expressions, e.g.:
[[[B0] T0] [[B1] T1] [D]] cond
-----------------------------------------
[B0] [T0] [[B1] [T1] [D] ifte] ifte
### Crosslinks
[ifte]