Abilities and functions
Use an ability to declare behaviour. Control when it runs with dependencies or a parent body. Define a function when several places need to call the same behaviour.
On this page
Abilities#
An ability is ability "kind" "Name". The kind comes from a provider; the name is yours and must be unique per kind. Abilities refer to each other as ability.kind.Name.
ability "loop" "Game" {
condition = !data.value.done.current
body = [ability.call.Turn, ability.print.Status]
}- Ownership. An ability listed in another's
body,then,run(and so on) runs there, and only there: it may sit in one list. - Order. Top-level abilities run in the order they are written;
depends_on = [ability.kind.Name, module.x]makes the order explicit. Inside a list the members run in dependency order: a member runs after the members it names independs_on, and members that depend on nothing keep the order they are written in.structop planandstructop graphshow the same order as the program. - Dependencies stay inside a list. A member of a list may depend on another member of the same list. A dependency on an ability outside the list is an error, and so is a dependency between two different lists of one ability, such as
thenandelseof anif, because only one of them runs at a time. A cycle inside a list is an error that names the abilities. enabled = falsekeeps an ability in the file but out of the program.
Here Second is written first in the list but waits for First, so the program prints first and then second, and the plan lists them in that order.
ability "if" "Choose" {
condition = true
then = [ability.print.Second, ability.print.First]
}
ability "print" "Second" {
message = "second"
depends_on = [ability.print.First]
}
ability "print" "First" {
message = "first"
}Functions#
ability "function" "twice" {
params = [{ name = "x", type = Int }]
returns = Int
return = x * 2
}
ability "call" "Show" {
function = ability.function.twice
args = [21]
result = ability.value.answer
}Functions take params, locals and a body (optional), may return an expression, and can be called inside expressions (${twice(var.n) + 1}). Structs are passed as Pointer parameters.
The guided tour shows how a program calls a function from a loop. Look up the attributes for an individual ability in the provider registry.