✓
Passing This code compiles and runs correctly.
Code
// One terminal can be referenced by several compounds without being
// redeclared. `Player` and `Enemy` do not each mint a separate health idea:
// both name the registered `Health`, and both pop values that the same
// `Health`-typed receiver accepts. The registry distinguishes declarations
// from references; references compose.
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(Player) {
health: Health
}
std/proto(Enemy) {
health: Health
}
std/list:new(Player)
| list players |> std/list:push(xs: players, health: 98.6) |> 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) |> 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 (Player, source: health: Health)
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Enemy, source: health: Health)
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