Skip to content

RCE language specification, draft 0.5

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 (54)

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

Syntax rejects (12)

Each of these is not in the language of the grammar and is refused before type checking.

spec/examples/reject/assign_in_expr.rce

Expected: refused at the parse stage by W-SYN-1: line 1: W-SYN-1 expected `)` (found `=`)

spec/examples/reject/bad_dedent.rce

Expected: refused at the parse stage by W-LEX-2: line 3: W-LEX-2 inconsistent dedent

spec/examples/reject/chained_compare.rce

Expected: refused at the parse stage by W-SYN-1: line 1: W-SYN-1 expected end of line (found `<`)

spec/examples/reject/class_keyword.rce

Expected: refused at the parse stage by W-SYN-1: line 1: W-SYN-1 expected a declaration (found `class`)

spec/examples/reject/if_expr_no_else.rce

Expected: refused at the parse stage by W-SYN-1: line 1: W-SYN-1 expected `else` (found end of line)

spec/examples/reject/kind_empty.rce

Expected: refused at the parse stage by W-SYN-1: line 2: W-SYN-1 expected indented block (found `fn`)

spec/examples/reject/missing_arrow_example.rce

Expected: refused at the parse stage by W-SYN-1: line 2: W-SYN-1 expected `->` (found integer `1`)

spec/examples/reject/state_no_fields.rce

Expected: refused at the parse stage by W-SYN-1: line 2: W-SYN-1 expected indented block (found `event`)

spec/examples/reject/step_no_on.rce

Expected: refused at the parse stage by W-SYN-1: line 4: W-SYN-1 expected `on` (found `E`)

spec/examples/reject/tab_indent.rce

Expected: refused at the parse stage by W-LEX-1: line 2: W-LEX-1 tab character

spec/examples/reject/try_in_then.rce

Expected: refused at the parse stage by W-SYN-1: line 1: W-SYN-1 expected an expression (found `try`)

spec/examples/reject/unterminated_string.rce

Expected: refused at the parse stage by W-SYN-1: line 1: W-SYN-1 unterminated string

Ill-typed programs (48)

Each of these parses but breaks a typing, ownership or well-formedness rule.

spec/examples/ill_typed/arena_escape.rce

Expected: refused at the check stage by W-REG-1: line 5: W-REG-1 a value in arena `a` escapes into `out`

spec/examples/ill_typed/assign_let.rce

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

spec/examples/ill_typed/borrow_escape.rce

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

spec/examples/ill_typed/device_emit.rce

Expected: refused at the check stage by W-DEV-1: line 3: W-DEV-1 emit inside a device region

spec/examples/ill_typed/device_extern.rce

Expected: refused at the check stage by W-DEV-1: line 5: W-DEV-1 `c_tick` is a foreign function and cannot be called in a device region

spec/examples/ill_typed/device_list.rce

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

spec/examples/ill_typed/extern_abi.rce

Expected: refused at the check stage by W-FFI-1: line 1: W-FFI-1 unknown ABI "stdcall" (only "C")

spec/examples/ill_typed/extern_in_pure.rce

Expected: refused at the check stage by W-EFF-1: line 3: W-EFF-1 `c_rand` is a foreign function: only main and task functions may call it

spec/examples/ill_typed/extern_owned_param.rce

Expected: refused at the check stage by W-FFI-1: line 1: W-FFI-1 foreign parameter type List[u8] is not bool, an integer, f64, &text, &[scalar] or &mut [scalar]

spec/examples/ill_typed/extern_spawn.rce

Expected: refused at the check stage by W-SPAWN-1: line 4: W-SPAWN-1 `c_work` is a foreign function and cannot be spawned

spec/examples/ill_typed/extern_text_result.rce

Expected: refused at the check stage by W-FFI-1: line 1: W-FFI-1 foreign result type text is not bool, an integer, f64 or ()

spec/examples/ill_typed/f32_literal.rce

Expected: refused at the check stage by W-TY-1: line 2: W-TY-1 `*` on f32 and f64: no implicit conversion

spec/examples/ill_typed/f32_mixed.rce

Expected: refused at the check stage by W-TY-1: line 2: W-TY-1 `+` on f32 and f64: no implicit conversion

spec/examples/ill_typed/fail_not_error.rce

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

spec/examples/ill_typed/int_mismatch.rce

Expected: refused at the check stage by W-TY-1: line 1: W-TY-1 `+` on u8 and i64: no implicit conversion

spec/examples/ill_typed/iter_effect.rce

Expected: refused at the check stage by W-ITER-1: line 1: W-ITER-1 iterator function `ticks` must be pure

spec/examples/ill_typed/iter_stored.rce

Expected: refused at the check stage by W-ITER-1: line 5: W-ITER-1 an iterator may only be the operand of `for` or the receiver of `.collect()`

spec/examples/ill_typed/iter_yield_type.rce

Expected: refused at the check stage by W-TY-1: line 2: W-TY-1 expected text, found ?0

spec/examples/ill_typed/linear_copy.rce

Expected: refused at the check stage by W-LIN-1: line 8: W-LIN-1 a linear value cannot be copied

spec/examples/ill_typed/linear_field.rce

Expected: refused at the check stage by W-LIN-1: line 4: W-LIN-1 struct field `a` cannot hold a linear value

spec/examples/ill_typed/linear_in_list.rce

Expected: refused at the check stage by W-LIN-1: line 4: W-LIN-1 a linear value cannot sit inside List

spec/examples/ill_typed/linear_loop.rce

Expected: refused at the check stage by W-LIN-1: line 0: W-LIN-1 linear `h` is moved inside a loop

spec/examples/ill_typed/linear_one_branch.rce

Expected: refused at the check stage by W-LIN-1: line 8: W-LIN-1 linear `h` is consumed on some branches but not others

spec/examples/ill_typed/linear_unconsumed.rce

Expected: refused at the check stage by W-LIN-1: line 0: W-LIN-1 linear `h` is not consumed at the end of its block

spec/examples/ill_typed/loop_limit_type.rce

Expected: refused at the check stage by 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/ill_typed/missing_return.rce

Expected: refused at the check stage by W-TY-1: line 1: W-TY-1 `f` can reach its end without returning i64

spec/examples/ill_typed/modify_while_iterating.rce

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

spec/examples/ill_typed/mut_alias.rce

Expected: refused at the check stage by W-OWN-2: line 6: W-OWN-2 `xs` is borrowed mutably and again in one call

spec/examples/ill_typed/non_exhaustive.rce

Expected: refused at the check stage by W-MATCH-1: line 6: W-MATCH-1 match is not exhaustive: missing Green

spec/examples/ill_typed/orphan_impl.rce

Expected: refused at the check stage by W-TRAIT-2: line 1: W-TRAIT-2 orphan impl: neither the trait nor the type is declared in this module

spec/examples/ill_typed/pure_send.rce

Expected: refused at the check stage by W-EFF-1: line 2: W-EFF-1 emit in a pure function

spec/examples/ill_typed/rec_not_structural.rce

Expected: refused at the check stage by 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/ill_typed/rec_same_arg.rce

Expected: refused at the check stage by W-REC-1: line 8: W-REC-1 recursion through loop_forever 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/ill_typed/recursion.rce

Expected: refused at the check stage by 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/ill_typed/select_after_type.rce

Expected: refused at the check stage by W-TY-1: line 2: W-TY-1 expected u64, found text

spec/examples/ill_typed/simd_len.rce

Expected: refused at the check stage by 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/ill_typed/simd_text.rce

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

spec/examples/ill_typed/spawn_borrow.rce

Expected: refused at the check stage by W-SPAWN-1: line 7: W-SPAWN-1 spawned tasks cannot receive borrows

spec/examples/ill_typed/state_no_init.rce

Expected: refused at the check stage by W-STATE-2: line 2: W-STATE-2 field `n` needs a comptime initial value

spec/examples/ill_typed/text_index_char.rce

Expected: refused at the check stage by W-TY-1: line 2: W-TY-1 cannot compare u8 with text

spec/examples/ill_typed/u64_mixed.rce

Expected: refused at the check stage by W-TY-1: line 2: W-TY-1 `+` on u64 and i64: no implicit conversion

spec/examples/ill_typed/unchecked_union.rce

Expected: refused at the check stage by W-TY-1: line 6: W-TY-1 expected i64, found i64 ! E

spec/examples/ill_typed/unhandled_event.rce

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

spec/examples/ill_typed/unknown_name.rce

Expected: refused at the check stage by W-NAME-1: line 1: W-NAME-1 unknown name `y`

spec/examples/ill_typed/unreachable_step.rce

Expected: refused at the check stage by W-STEP-4: line 7: W-STEP-4 unreachable: the unguarded step at line 6 already handles S on E

spec/examples/ill_typed/unsafe_name.rce

Expected: refused at the check stage by W-SAFE-1: line 2: W-SAFE-1 `unsafe` is refused

spec/examples/ill_typed/use_after_move.rce

Expected: refused at the check stage by W-OWN-1: line 5: W-OWN-1 `s` is used after it was moved

spec/examples/ill_typed/yield_outside.rce

Expected: refused at the check stage by W-ITER-1: line 2: W-ITER-1 yield outside an iterator function

Inadmissible programs (16)

Each of these type-checks but fails the admission gate: an example, a check, a comptime block or a constant does not hold when evaluated.

spec/examples/inadmissible/arena_size_limit.rce

Expected: refused at the admit stage by W-INT-1: line 8: W-INT-1 check: trap: size limit

spec/examples/inadmissible/bslice_boundary.rce

Expected: refused at the admit stage by W-INT-1: line 1: W-INT-1 check: trap: not a char boundary

spec/examples/inadmissible/comptime_check.rce

Expected: refused at the admit stage by W-CT-1: line 3: W-CT-1 comptime block in `f`: trap: check failed

spec/examples/inadmissible/const_overflow.rce

Expected: refused at the admit stage by W-CT-1: line 1: W-CT-1 const `BIG`: trap: overflow: 300 is outside u8

spec/examples/inadmissible/f32_overflow.rce

Expected: refused at the admit stage by W-INT-1: line 1: W-INT-1 check: trap: non-finite float

spec/examples/inadmissible/false_check.rce

Expected: refused at the admit stage by W-INT-1: line 2: W-INT-1 check is false

spec/examples/inadmissible/guard_trap.rce

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

spec/examples/inadmissible/iter_unbounded.rce

Expected: refused at the admit stage by W-INT-1: line 9: W-INT-1 check: trap: loop bound

spec/examples/inadmissible/literal_out_of_range.rce

Expected: refused at the check stage by W-LEX-3: line 1: W-LEX-3 literal 300 is outside u8

spec/examples/inadmissible/loop_bound.rce

Expected: refused at the admit stage by W-INT-1: line 2: W-INT-1 check: trap: loop bound

spec/examples/inadmissible/loop_limit_low.rce

Expected: refused at the admit stage by W-INT-1: line 9: W-INT-1 check: trap: loop bound

spec/examples/inadmissible/state_init_overflow.rce

Expected: refused at the admit stage by W-CT-1: line 0: W-CT-1 state initializer: trap: overflow: 256 is outside u8

spec/examples/inadmissible/u64_underflow.rce

Expected: refused at the admit stage by W-INT-1: line 4: W-INT-1 check: trap: overflow: -1 is outside u64

spec/examples/inadmissible/unexpected_refusal.rce

Expected: refused at the admit stage by W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Dec) refused: trap(overflow: -1 is outside u64)

spec/examples/inadmissible/wrong_example_value.rce

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

spec/examples/inadmissible/wrong_refusal.rce

Expected: refused at the admit stage by W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Dec) refused: Underflow

Built from spec commit 49fa9af. 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.