udt_particle

Nested UDTs with container-backed fields.

udt Vec2 {
    real64 x
    real64 y
}

udt Particle {
    Vec2 pos
    Vec2 vel
    real64 mass
    dict[string, int64] tags
}

function advance(Particle p, real64 dt) -> Particle {
    p.pos = Vec2{p.pos.x + dt * p.vel.x, p.pos.y + dt * p.vel.y}
    return p
}

program main {
    Particle p = Particle{Vec2{1.0, 2.0}, Vec2{0.5, -1.0}, 3.0, dict[string, int64]{"id": 7}}

    Particle q = advance(p, 0.1)

    print(p.pos.x, p.pos.y)
    print(q.pos.x, q.pos.y)
    print(q.mass, q.tags["id"])
}