ava/expressions.md

45 lines
950 B
Markdown

# Expressions
_Expressions_ are the basis of programming in Ava. An expression is some code
that will produce a _value_ when evaluated.
## Syntax
Most non-[Definition](definitions.md) code is considered an expression.
Expressions include:
- Literals
- Variables
- Function Calls
- Control Expressions
In general, using a Literal or a Variable for an expression wraps that value in
a `pure` function that returns the value when evaluated.
## Control Expressions
### If Then
The `if/then` expression expects an expression that returns a _Boolean Value_.
That expression is evaluated. If it evaluates to `true`, the `then` expression
is evaluated. Otherwise the `else` expression is evaluated.
```
if <boolean expr> then <expr> else <expr>
```
### Do Yield
TODO: This is incomplete
The `do/yield` expression allows for imperative composition of monadic
expressions.
```
do
x <- foo()
y <- bar()
_ <- baz()
yield
x + y
```