Quick Reference
A quick reference guide to Turn's core primitives, syntax grammar, expressions, and built-in tools.
Core Primitives
First-class unit of behavior. turn { ... } defines a control cycle representing one step of agent execution. Closures are turn(args) -> Type { ... }.
Bounded working context managed by the runtime. The language enforces |context| ≤ N to prevent unbounded lists.
Persistent process memory as a primitive store. remember(key, value) writes; recall(key) reads. Returns null when key is missing.
External effects suspend execution and resume with a value. call(tool_name, arg) serves as the single suspension boundary enabling deterministic replay.
Probabilistic effect returning a typed value. infer Type { prompt } invokes an LLM with cognitive type safety where the runtime validates the schema.
Explicit durable checkpoint. suspend; writes the entire VM state to disk for orthogonal persistence.
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.fieldfor structs and maps - Control flow:
if expr { ... } else { ... },while expr { ... } - Structs:
struct Name { field: Type, ... };
Built-in Tools (Alpha)
| Tool | Purpose |
|---|---|
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
- Types and Errors Every type in Turn and the monadic error model.
- Error Handling Monadic error routing with Result and Option.