Skip to content
Skip to content

RCE language specification, draft 0.9

Example programs

These are the programs in spec/examples/. Each cell shows the result the reference checker gives for it. Edit any program and press Run, or Ctrl+Enter, to check your version. In a code cell, Tab inserts four spaces; press Escape and then Tab to leave the cell.

Accepted programs (60)

Each of these is accepted: it parses, type-checks, and every example and check inside it holds.

spec/examples/01_counter.rce

Expected: accepted

spec/examples/02_hello_main.rce

Expected: accepted

spec/examples/03_fib_loop.rce

Expected: accepted

spec/examples/04_bank_account.rce

Expected: accepted

spec/examples/05_kind_match.rce

Expected: accepted

spec/examples/06_option.rce

Expected: accepted

spec/examples/07_error_union.rce

Expected: accepted

spec/examples/08_traits.rce

Expected: accepted

spec/examples/09_generics.rce

Expected: accepted

spec/examples/10_comptime.rce

Expected: accepted

spec/examples/11_arena.rce

Expected: accepted

spec/examples/12_borrow.rce

Expected: accepted

spec/examples/13_spawn_chan.rce

Expected: accepted

spec/examples/14_select.rce

Expected: accepted

spec/examples/15_actor.rce

Expected: accepted

spec/examples/16_multi_region.rce

Expected: accepted

spec/examples/17_traffic_light.rce

Expected: accepted

spec/examples/18_while_bound.rce

Expected: accepted

spec/examples/19_floats.rce

Expected: accepted

spec/examples/20_strings.rce

Expected: accepted

spec/examples/21_maps.rce

Expected: accepted

spec/examples/22_tuples.rce

Expected: accepted

spec/examples/23_patterns.rce

Expected: accepted

spec/examples/24_lambda.rce

Expected: accepted

spec/examples/25_labels.rce

Expected: accepted

spec/examples/27_bitops.rce

Expected: accepted

spec/examples/28_slices.rce

Expected: accepted

spec/examples/29_nested_kind.rce

Expected: accepted

spec/examples/30_state_machine_guarded.rce

Expected: accepted

spec/examples/31_inventory.rce

Expected: accepted

spec/examples/32_comptime_block.rce

Expected: accepted

spec/examples/33_in_operator.rce

Expected: accepted

spec/examples/34_chan_types.rce

Expected: accepted

spec/examples/35_nested_if.rce

Expected: accepted

spec/examples/36_multiline_brackets.rce

Expected: accepted

spec/examples/37_actor_spawn.rce

Expected: accepted

spec/examples/38_hex_bin.rce

Expected: accepted

spec/examples/39_structural_recursion.rce

Expected: accepted

spec/examples/40_extern.rce

Expected: accepted

spec/examples/41_arena_bound_wrapping.rce

Expected: accepted

spec/examples/42_f32.rce

Expected: accepted

spec/examples/43_simd_lanes.rce

Expected: accepted

spec/examples/44_device_region.rce

Expected: accepted

spec/examples/45_byte_text.rce

Expected: accepted

spec/examples/46_u64.rce

Expected: accepted

spec/examples/47_select_fair.rce

Expected: accepted

spec/examples/48_linear_handle.rce

Expected: accepted

spec/examples/49_loop_limit.rce

Expected: accepted

spec/examples/50_iterators.rce

Expected: accepted

spec/examples/51_refined_input.rce

Expected: accepted

spec/examples/52_context_text.rce

Expected: accepted

spec/examples/53_capability.rce

Expected: accepted

spec/examples/54_secret.rce

Expected: accepted

spec/examples/55_rcedb.rce

Expected: accepted

spec/examples/56_utf8.rce

Expected: accepted

spec/examples/57_float_vectors.rce

Expected: accepted

spec/examples/58_float_keys.rce

Expected: accepted

spec/examples/59_dim_redundant_field.rce

Expected: accepted

spec/examples/60_dim_hidden_period.rce

Expected: accepted

spec/examples/61_dim_minimal.rce

Expected: accepted

Syntax: requires change (13)

Each of these is not in the language of the grammar, so it requires change before type checking; the result names the rule.

spec/examples/change/syntax/assign_in_expr.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected `)` (found `=`)

spec/examples/change/syntax/bad_dedent.rce

Expected: requires change at the parse stage, rule W-LEX-2: line 3: W-LEX-2 inconsistent dedent

spec/examples/change/syntax/chained_compare.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected end of line (found `<`)

spec/examples/change/syntax/class_keyword.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected a declaration (found `class`)

spec/examples/change/syntax/if_expr_no_else.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected `else` (found end of line)

spec/examples/change/syntax/kind_empty.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 2: W-SYN-1 expected indented block (found `fn`)

spec/examples/change/syntax/law_two_claims.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 12: W-SYN-1 a law has exactly one `always` or `every step` line (found `always`)

spec/examples/change/syntax/missing_arrow_example.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 2: W-SYN-1 expected `->` (found integer `1`)

spec/examples/change/syntax/state_no_fields.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 2: W-SYN-1 expected indented block (found `event`)

spec/examples/change/syntax/step_no_on.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 4: W-SYN-1 expected `on` (found `E`)

spec/examples/change/syntax/tab_indent.rce

Expected: requires change at the parse stage, rule W-LEX-1: line 2: W-LEX-1 tab character

spec/examples/change/syntax/try_in_then.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected an expression (found `try`)

spec/examples/change/syntax/unterminated_string.rce

Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 unterminated string

Ill-typed programs (55)

Each of these parses but breaks a typing, ownership or well-formedness rule, so it requires change; the result names the rule.

spec/examples/change/types/arena_escape.rce

Expected: requires change at the check stage, rule W-REG-1: line 5: W-REG-1 a value in arena `a` escapes into `out`

spec/examples/change/types/assign_let.rce

Expected: requires change at the check stage: line 3: W-PLACE `x` is not mutable (declare it with var)

spec/examples/change/types/borrow_escape.rce

Expected: requires change at the check stage, rule W-OWN-3: line 1: W-OWN-3 a returned borrow must derive from a borrowed parameter (R-RET)

spec/examples/change/types/device_emit.rce

Expected: requires change at the check stage, rule W-DEV-1: line 3: W-DEV-1 emit inside a device region

spec/examples/change/types/device_extern.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_tick` must take `&World` as its first parameter, and only there

spec/examples/change/types/device_list.rce

Expected: requires change at the check stage, rule W-DEV-1: line 3: W-DEV-1 a device region holds fixed-size values only, found List[u64]

spec/examples/change/types/extern_abi.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_f` must take `&World` as its first parameter, and only there

spec/examples/change/types/extern_in_pure.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_rand` must take `&World` as its first parameter, and only there

spec/examples/change/types/extern_owned_param.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_take` must take `&World` as its first parameter, and only there

spec/examples/change/types/extern_spawn.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_work` must take `&World` as its first parameter, and only there

spec/examples/change/types/extern_text_result.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_name` must take `&World` as its first parameter, and only there

spec/examples/change/types/f32_literal.rce

Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 `*` on f32 and f64: no implicit conversion

spec/examples/change/types/f32_mixed.rce

Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 `+` on f32 and f64: no implicit conversion

spec/examples/change/types/fail_not_error.rce

Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 fail needs an error, found ?0

spec/examples/change/types/graph_attention.rce

Expected: requires change at the check stage, rule W-GRAPH-1: line 13: W-GRAPH-1 `tensor.attention_causal`: q [[f64; 2]; 2], k [[f64; 3]; 2], v [[f64; 2]; 2]: k has q's last length, v as many rows as k, and the heads of q are a multiple of those of k and v

spec/examples/change/types/graph_integer.rce

Expected: requires change at the check stage, rule W-GRAPH-2: line 12: W-GRAPH-2 `tensor.exp` takes tensors of f32 or f64, found [i32; 3]

spec/examples/change/types/graph_level.rce

Expected: requires change at the check stage, rule W-GRAPH-3: line 11: W-GRAPH-3 `tensor.round_bf16` has level lossy, weaker than the level exact in force here; declare it with `tensor.lossy(...)` around the operation

spec/examples/change/types/graph_operand.rce

Expected: requires change at the check stage, rule W-GRAPH-2: line 11: W-GRAPH-2 an operand of `tensor.relu` has type List[f64]; a tensor is an array of fixed length, possibly nested, of f32, f64, i8 or i32

spec/examples/change/types/graph_quantize.rce

Expected: requires change at the check stage, rule W-GRAPH-3: line 12: W-GRAPH-3 `tensor.round_q8_0` has level lossy, weaker than the level exact in force here; declare it with `tensor.lossy(...)` around the operation

spec/examples/change/types/graph_shape.rce

Expected: requires change at the check stage, rule W-GRAPH-1: line 11: W-GRAPH-1 `tensor.matvec`: the matrix [[f64; 3]; 2] has 3 columns and the vector [f64; 2] has 2 elements; they must be equal

spec/examples/change/types/int_mismatch.rce

Expected: requires change at the check stage, rule W-TY-1: line 1: W-TY-1 `+` on u8 and i64: no implicit conversion

spec/examples/change/types/iter_effect.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 1: W-UNUSED-1 `c` is never read; remove it or name it `_c`

spec/examples/change/types/iter_stored.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 5: W-UNUSED-1 `it` is never read; remove it or name it `_it`

spec/examples/change/types/iter_yield_type.rce

Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 expected text, found ?0

spec/examples/change/types/let_borrow_write.rce

Expected: requires change at the check stage, rule W-OWN-2: line 7: W-OWN-2 `n` is written while `a` (line 6) borrows `n` with `&mut`, and `a` is used again at line 8: end the borrow before this use (5.6 [No-Alias-Write])

spec/examples/change/types/linear_copy.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there

spec/examples/change/types/linear_field.rce

Expected: requires change at the check stage, rule W-LIN-1: line 4: W-LIN-1 struct field `a` cannot hold a linear value

spec/examples/change/types/linear_in_list.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 4: W-UNUSED-1 `hs` is never read; remove it or name it `_hs`

spec/examples/change/types/linear_loop.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there

spec/examples/change/types/linear_one_branch.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there

spec/examples/change/types/linear_unconsumed.rce

Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there

spec/examples/change/types/loop_limit_type.rce

Expected: requires change at the check stage, rule W-LOOP-1: line 1: W-LOOP-1 LOOP_LIMIT must be declared `const LOOP_LIMIT: u64 = n` with a positive literal n

spec/examples/change/types/missing_return.rce

Expected: requires change at the check stage, rule W-TY-1: line 1: W-TY-1 `f` can reach its end without returning i64

spec/examples/change/types/modify_while_iterating.rce

Expected: requires change at the check stage, rule W-OWN-2: line 3: W-OWN-2 `xs` is borrowed by the for loop and cannot be modified inside it

spec/examples/change/types/mut_alias.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 1: W-UNUSED-1 `a` is never read; remove it or name it `_a`

spec/examples/change/types/non_exhaustive.rce

Expected: requires change at the check stage, rule W-MATCH-1: line 6: W-MATCH-1 match is not exhaustive: missing Green

spec/examples/change/types/orphan_impl.rce

Expected: requires change at the check stage, rule W-TRAIT-2: line 1: W-TRAIT-2 orphan impl: neither the trait nor the type is declared in this module

spec/examples/change/types/pure_send.rce

Expected: requires change at the check stage, rule W-EFF-1: line 2: W-EFF-1 emit in a pure function

spec/examples/change/types/rec_not_structural.rce

Expected: requires change at the check stage, rule W-REC-1: line 4: W-REC-1 recursion through countdown has no decreasing measure (6.7): no layers of summed measures, each kept by every call not yet done and shrunk by at least one, leave the remaining calls without a cycle, and a cycle of its calls passes through no function declared with `bound`

spec/examples/change/types/rec_same_arg.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 8: W-UNUSED-1 `l` is never read; remove it or name it `_l`

spec/examples/change/types/recursion.rce

Expected: requires change at the check stage, rule W-REC-1: line 1: W-REC-1 recursion through f, g has no decreasing measure (6.7): no layers of summed measures, each kept by every call not yet done and shrunk by at least one, leave the remaining calls without a cycle, and a cycle of its calls passes through no function declared with `bound`

spec/examples/change/types/select_after_type.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 2: W-UNUSED-1 `x` is never read; remove it or name it `_x`

spec/examples/change/types/simd_len.rce

Expected: requires change at the check stage, rule W-SIMD-1: line 2: W-SIMD-1 lane-wise `+` needs two arrays of one fixed length, found [i32; 3] and [i32; 4]

spec/examples/change/types/simd_text.rce

Expected: requires change at the check stage, rule W-SIMD-1: line 2: W-SIMD-1 lane-wise `*` needs numeric lanes, found text

spec/examples/change/types/spawn_borrow.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 1: W-UNUSED-1 `xs` is never read; remove it or name it `_xs`

spec/examples/change/types/state_no_init.rce

Expected: requires change at the check stage, rule W-STATE-2: line 2: W-STATE-2 field `n` needs a comptime initial value

spec/examples/change/types/text_index_char.rce

Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 cannot compare u8 with text

spec/examples/change/types/u64_mixed.rce

Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 `+` on u64 and i64: no implicit conversion

spec/examples/change/types/unchecked_union.rce

Expected: requires change at the check stage, rule W-TY-1: line 6: W-TY-1 expected i64, found i64 ! E

spec/examples/change/types/unhandled_event.rce

Expected: requires change at the check stage, rule W-STEP-2: line 5: W-STEP-2 event `Dec` is handled by no step or actor: δ would not be total

spec/examples/change/types/unknown_name.rce

Expected: requires change at the check stage, rule W-NAME-1: line 1: W-NAME-1 unknown name `y`

spec/examples/change/types/unreachable_step.rce

Expected: requires change at the check stage, rule W-STEP-4: line 7: W-STEP-4 unreachable: the unguarded step at line 6 already handles S on E

spec/examples/change/types/unsafe_name.rce

Expected: requires change at the check stage, rule W-SAFE-1: line 2: W-SAFE-1 `unsafe` is not admitted

spec/examples/change/types/use_after_move.rce

Expected: requires change at the check stage, rule W-LEN-1: line 1: W-LEN-1 text has no unqualified `len`: use `len_bytes` or `len_chars` (F.5.2)

spec/examples/change/types/yield_outside.rce

Expected: requires change at the check stage, rule W-ITER-1: line 2: W-ITER-1 yield outside an iterator function

Inadmissible programs (18)

Each of these type-checks but does not pass admission: an example, a check, a comptime block or a constant does not hold when evaluated, so it requires change.

spec/examples/change/admission/arena_size_limit.rce

Expected: requires change at the admit stage, rule W-INT-1: line 8: W-INT-1 check: trap: size limit

spec/examples/change/admission/bslice_boundary.rce

Expected: requires change at the admit stage, rule W-INT-1: line 1: W-INT-1 check: trap: not a char boundary

spec/examples/change/admission/comptime_check.rce

Expected: requires change at the admit stage, rule W-CT-1: line 3: W-CT-1 comptime block in `f`: trap: check failed

spec/examples/change/admission/const_overflow.rce

Expected: requires change at the admit stage, rule W-CT-1: line 1: W-CT-1 const `BIG`: trap: overflow: 300 is outside u8

spec/examples/change/admission/f32_overflow.rce

Expected: requires change at the admit stage, rule W-INT-1: line 1: W-INT-1 check: trap: non-finite float

spec/examples/change/admission/false_check.rce

Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 check is false

spec/examples/change/admission/frame_no_tabindex.rce

Expected: requires change at the admit stage, rule W-UI-1: line 6: W-UI-1 the example's 1 frames: WCAG 1.3.1 undecided: needs human attestation: whether every structure and relationship shown is expressed by roles and states

spec/examples/change/admission/guard_trap.rce

Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Go) kept: trap(division by zero)

spec/examples/change/admission/iter_unbounded.rce

Expected: requires change at the admit stage, rule W-INT-1: line 9: W-INT-1 check: trap: loop bound

spec/examples/change/admission/law_fails.rce

Expected: requires change at the admit stage, rule W-LAW-1: line 5: W-LAW-1 law you_cant_win fails after 9 events (exhaustive, alphabet 4 complete, 86 states explored): the claim is false example Up, Up, Up, Up, Right, Right, Right, Right, Right -> won

spec/examples/change/admission/literal_out_of_range.rce

Expected: requires change at the check stage, rule W-LEX-3: line 1: W-LEX-3 literal 300 is outside u8

spec/examples/change/admission/loop_bound.rce

Expected: requires change at the check stage, rule W-UNUSED-1: line 5: W-UNUSED-1 `k` is never read; remove it or name it `_k`

spec/examples/change/admission/loop_limit_low.rce

Expected: requires change at the admit stage, rule W-INT-1: line 9: W-INT-1 check: trap: loop bound

spec/examples/change/admission/state_init_overflow.rce

Expected: requires change at the admit stage, rule W-CT-1: line 0: W-CT-1 state initializer: trap: overflow: 256 is outside u8

spec/examples/change/admission/u64_underflow.rce

Expected: requires change at the admit stage, rule W-INT-1: line 4: W-INT-1 check: trap: overflow: -1 is outside u64

spec/examples/change/admission/unexpected_kept.rce

Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Dec) kept: trap(overflow: -1 is outside u64)

spec/examples/change/admission/wrong_example_value.rce

Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 example does not hold: final value is 2, expected 3

spec/examples/change/admission/wrong_kept_reason.rce

Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Dec) kept: Underflow

Built from spec commit 1762fb4b. Code cells run the reference checker rce-check, written in Rust and compiled to WebAssembly, inside your browser; nothing is sent to a server. Read-aloud uses the Kokoro-82M model (Apache-2.0), served from this site and run in your browser.