Variables & Types
Give inputs and results explicit types.
Assignment creates a local variable and infers its type from the expression. Explicit public parameter and return types let both compiler and kernel validate data.
Complete example
Save the example as types.aal
agent Tutorial is Agent
public
ability run(name: String?, count: Int) -> String effects()
next = count + 1
label = if name == None then "Guest" else name
return "{label}: {next}"Syntax explained
-
Basic types include
String,Int,FloatandBool.Intis arbitrary precision;Floatis finite 64-bit floating point. -
String?permits aStringorNone. CheckforNonebefore using the value. -
You cannot freely reassign an integer variable to a string. An omitted annotation introduces
Any, not a static type guarantee.
Build and run
cargo run --locked --bin aalc -- check types.aal
cargo run --locked --bin aalc -- build types.aal -o types.aalc
cargo run --locked --bin aalc -- run types.aalc \
--agent Tutorial --ability run \
--args '{"name":null,"count":2}' \
--state-dir .aal-tutorial/types --invocation types-1Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.
"Guest: 3"Try it yourself
Set name to Ada and count to 9. Run with a new invocation ID; the result should be Ada: 10.