Playground Documentation Challenges Full Docs

Scopes

Scope structure, braces, chaining, and bare blocks

Overview

Formall code is organized into nested scopes. Five commands create scopes: type, for, if, lock, and rule. Every declaration and proof result is scoped to the scope where it was delivered.

Braces Are Optional

A scope-creating command always creates a scope, whether or not you use curly braces { }. Braces are just syntax for grouping multiple commands into one scope. Without braces, the scope contains only the next command (and its scope). These two forms are equivalent:

With and without braces

Both forms produce exactly the same scope tree. Braces simply let you put more commands inside a scope.

▶ Run
ℹ
This is the same rule as in C-like languages: if(x) if(y) f(); is equivalent to if(x) { if(y) { f(); } }.

Chaining

Without braces, scope-creating commands naturally chain — each one wraps around what follows. The chain ends when something that opens no scope — a proof, a call — is done, or when a semicolon ; is encountered:

Chaining

▶ Run

As in C, a semicolon after a statement ends the whole chain: in for(…) if(…) <…>; the ; closes the proof, and with it the if and the for.

Declarations

A chain that consists only of scope commands (type, for, if, lock, rule, import) and ends with ; is a declaration. It lasts until the end of the enclosing block or file, like int x; in C: later semicolons end only their own statements. A chain left open at the end of a file is a declaration as well.

Declarations

▶ Run

A declaration made inside a block ends with the block. This is how a file declares its language once and then states its theorems at the top level — and how import works.

Labels before a chained command apply to that command:

Labels on chained commands

▶ Run

Comma-separated Commands

Non-scope commands can be separated by commas within the same scope. Each command executes independently:

Comma-separated commands

▶ Run
⚠
Scope-creating commands (type, for, if, lock, rule) cannot be comma-separated. They must be chained or placed in their own scopes.

Bare Blocks

Curly braces can be used without any command, creating an anonymous scope. Anything declared inside is not visible outside:

Bare block

▶ Run

Scope Hierarchy

Scopes form a tree. Each scope may contain child scopes. This tree determines:

  • Visibility — atoms, labels, and rules are visible in their declaring scope and all descendants
  • Statement access — statements are accessible from the scope where they were delivered and from nested scopes
  • Label scope visibility — when reading a label, only statements on the path from the current scope up to the label's declaration are included (see Labels)
  • Boundary rules — a call that takes the blocks its proof stands in takes for and if only, never a type, lock or rule