Skip to content

Lists & Maps

Store multiple values and look them up by key.

List<T> stores elements of one type; Map<K,V> associates keys with values. Here we count labels and write the result into a map.

Complete example

Save the example as collections.aal

collections.aal
agent Tutorial is Agent
  public
    ability run() -> Int effects()
      labels = ["docs", "tools"]
      labels.append("agents")
      counts = Map<String,Int>{"total": 0}
      counts["total"] = labels.len()
      return counts["total"]
Download .aal

Syntax explained

  1. Write a list as ["docs", "tools"]. Access with items[0] and add with .append(value).

  2. An explicit map is Map<String,Int>{"total": 0}; read or write using map["total"].

  3. Lists and records have value semantics: assignment and calls clone owned values. Local collection mutation does not require memory.write.

Build and run

Terminal
cargo run --locked --bin aalc -- check collections.aal

cargo run --locked --bin aalc -- build collections.aal -o collections.aalc

cargo run --locked --bin aalc -- run collections.aalc \
  --agent Tutorial --ability run \
  --args '{}' \
  --state-dir .aal-tutorial/collections --invocation collections-1

Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.

Expected result
3

Try it yourself

Add labels.append("notes"), rebuild and use a new invocation ID. The returned count should change from 3 to 4.

Language source and specification