Playground
Start
The compiler front end runs in this tab as WebAssembly. Files are stored in this browser.
Templates
No problems. The compiler will list what it refuses here.
Nothing has run yet.
These lines reach readLine(), one per call. After the last one it answers None.
?The compiler runs in this tab as WebAssembly, and so does the program it compiles. Nothing is uploaded. A program is stopped after five seconds, and a recursion that outgrows the tab's stack stops with the error
vyrn run gives. The tab has no filesystem and no arguments. One file runs, plus std/, which is built in.Loading the compiler… 0Ln 1, Col 1Spaces: 2UTF-8VyrnShift+F10 Runfn main() -> Int64 {
print("hello")
return 0
}
type Age = Int64 where value >= 18
fn admit(n: Int64) -> Int64 {
// `Age?(n)` is None when the rule fails, so untrusted input never traps.
return match Age?(n) {
Some(a) => a,
None => 0 - 1,
}
}
fn main() -> Int64 {
print(admit(30))
print(admit(5))
// Uncomment the next line. The compiler refuses it, and says why.
// let bad = Age(5)
return 0
}
type Ticket = { id: Int64, seats: Int64 }
fn seatCount(t: read Ticket) -> Int64 { return t.seats }
fn addSeat(t: modify Ticket) { t.seats = t.seats + 1 }
fn redeem(t: consume Ticket) -> Int64 { return t.id }
fn main() -> Int64 {
let mut t = Ticket { id: 7, seats: 2 }
print(seatCount(t))
addSeat(t)
print(seatCount(t))
print(redeem(t))
// `t` was consumed above. Name it again and the compiler refuses:
// print(seatCount(t))
return 0
}
fn fib(n: Int64) -> Int64 {
if n < 2 { return n }
return fib(n - 1) + fib(n - 2)
}
fn main() -> Int64 {
let mut i = 0
while i <= 15 {
print(fib(i))
i = i + 1
}
return 0
}
// The lines in the standard input box below arrive here, one per call.
// At the end of them `readLine()` answers None, exactly as a pipe does.
fn main() -> Int64 {
let mut n = 0
while let Some(line) = readLine() {
print("\{n}: \{line}")
n = n + 1
}
print("\{n} line(s)")
return 0
}
// A trap writes to standard error and the program exits non-zero — the same
// channels a terminal gives it.
fn main() -> Int64 {
print("before")
panic("this is a trap")
return 0
}
alpha beta gamma