xpile 0.1.615

Polyglot transpile workbench (Python/C/C++/Rust/Ruchy/Lean ↔ Rust/Ruchy/PTX/WGSL/SPIR-V) with provable contracts at every layer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def lookup(d: dict[str, int], k: str) -> int:
    # Fresh binding: `v` is introduced by the try (a single `let v = <try>`).
    try:
        v = d[k]
    except KeyError:
        v = -1
    return v


def accumulate(xs: list[int], i: int) -> int:
    # `base` is bound before the try and READ inside both arms, so the try
    # reassigns an already-bound (`mut`) name without a dead initial value.
    base = 10
    try:
        base = base + xs[i]
    except:
        base = base * 2
    return base