Conditions & Match
Turn inputs into explicit decisions.
if chooses a branch from a Boolean condition. An if ... then ... else ... expression needs both results. match selects the first matching arm in source order.
Complete example
Save the example as control-flow.aal
agent Tutorial is Agent
public
ability run(score: Int) -> String effects()
require score >= 0, "Score must be nonnegative"
grade = if score >= 6 then "ready" else "revise"
return match grade
"ready" -> "Publish"
_ -> "Review again"Syntax explained
-
Use ==, !=, <, <=, >, >=, in and not in. Comparisons may chain: 40 <= area < 100. Combine conditions with and or or.
-
requirecondition, "message" fails withE_REQUIREMENTwhen false. Place it before the operation it protects. -
matchsupports literals, nullary enums,Noneand bindings. Put the _ catch-all last. Destructuring patterns are not supported.
Build and run
cargo run --locked --bin aalc -- check control-flow.aal
cargo run --locked --bin aalc -- build control-flow.aal -o control-flow.aalc
cargo run --locked --bin aalc -- run control-flow.aalc \
--agent Tutorial --ability run \
--args '{"score":7}' \
--state-dir .aal-tutorial/control-flow --invocation control-flow-1Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.
"Publish"Try it yourself
Try score 3 to get Review again, then -1 to trigger require before grade is computed. Use a new invocation ID for each request.