✓
Passing This code compiles and runs correctly.
Code
// The shared terminal keeps its identity through nesting: Player and Enemy
// both expand a `pos: Position` alongside their direct `health: Health`,
// and popped values from both lists flow into the one Health-typed
// receiver. Chains preserve what terminals promise globally.
import std/io
import std/proto
import std/list
std/proto:f64(Health)
pub tor report-health { health: Health } -> Health
report-health -> health
std/proto(Position) {
x: f32
y: f32
}
std/proto(Player) {
health: Health
pos: Position
}
std/proto(Enemy) {
health: Health
pos: Position
}
std/list:new(Player)
| list players |> std/list:push(xs: players, health: 98.6, pos_x: 0.0, pos_y: 0.0) |> std/list:pop(xs: players)
| item player |> report-health(player.health): player_out |> std/io:print.ln("player {{ player_out:d }}") |> std/list:free(xs: players)
| empty |> std/io:print.ln("player EMPTY") |> std/list:free(xs: players)
| err e |> std/io:print.ln("ERR {{ e:s }}")
std/list:new(Enemy)
| list enemies |> std/list:push(xs: enemies, health: 72.5, pos_x: 0.0, pos_y: 0.0) |> std/list:pop(xs: enemies)
| item enemy |> report-health(enemy.health): enemy_out |> std/io:print.ln("enemy {{ enemy_out:d }}") |> std/list:free(xs: enemies)
| empty |> std/io:print.ln("enemy EMPTY") |> std/list:free(xs: enemies)
| err e |> std/io:print.ln("ERR {{ e:s }}")
Actual
player 98.6
enemy 72.5
Expected output
player 98.6
enemy 72.5
Flows
flow ~f64 click a branch to expand · @labels scroll to their anchor
f64 (expr: Health)
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Position, source: x: f32
y: f32)
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Player, source: health: Health
pos: Position)
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Enemy, source: health: Health
pos: Position)
flow ~new click a branch to expand · @labels scroll to their anchor
new (Player)
flow ~new click a branch to expand · @labels scroll to their anchor
new (Enemy)
Test Configuration
MUST_RUN