Quick Reference

A quick reference guide to Turn's core primitives, syntax grammar, expressions, and built-in tools.


Core Primitives

turn

First-class unit of behavior. turn { ... } defines a control cycle representing one step of agent execution. Closures are turn(args) -> Type { ... }.

context.append

Bounded working context managed by the runtime. The language enforces |context| ≤ N to prevent unbounded lists.

remember / recall

Persistent process memory as a primitive store. remember(key, value) writes; recall(key) reads. Returns null when key is missing.

call

External effects suspend execution and resume with a value. call(tool_name, arg) serves as the single suspension boundary enabling deterministic replay.

infer

Probabilistic effect returning a typed value. infer Type { prompt } invokes an LLM with cognitive type safety where the runtime validates the schema.

suspend

Explicit durable checkpoint. suspend; writes the entire VM state to disk for orthogonal persistence.

spawn

Actor-style concurrency. spawn turn() { ... } creates an isolated process with its own state and mailbox.


Expressions & Statements

  • Literals: 42, "hello", true, false, null, [1, 2, 3], { key: val }
  • Variables: let id = expr;
  • Operators: +, ==, !=, <, >, <=, >=, and, or, !
  • Indexing: expr[index] for lists and maps
  • Member access: expr.field for structs and maps
  • Control flow: if expr { ... } else { ... }, while expr { ... }
  • Structs: struct Name { field: Type, ... };

Built-in Tools (Alpha)

ToolPurpose
echo(val)Returns the value (prints to stdout)
sleep(seconds)Pauses execution
http_get(url)GET request
http_post({url, body})POST with JSON body
json_parse(str)Parse JSON string to Value
json_stringify(val)Value to JSON string
fs_read_blob(path)Returns a Blob resolving the MIME-type
load_driver(path)Maps driver configurations into env vars
env_set(key, val)Sets an environment variable
sys_exec({bin, ...args})Native CLI execution (keys mapped to string args)

Next Steps