21 lines
738 B
Plaintext
21 lines
738 B
Plaintext
fn parsePositive(s: String): Int with {Fail, Console} = {
|
|
Console.print("Parsing \"" + s + "\"...")
|
|
if s == "42" then 42 else if s == "100" then 100 else Fail.fail("Invalid number: " + s)
|
|
}
|
|
|
|
fn safeDivide(a: Int, b: Int): Int with {Fail, Console} = {
|
|
Console.print("Dividing " + toString(a) + " by " + toString(b) + "...")
|
|
if b == 0 then Fail.fail("Division by zero") else a / b
|
|
}
|
|
|
|
fn main(): Unit with {Console} = {
|
|
let n1 = run parsePositive("42") with {}
|
|
Console.print("Result: " + toString(n1))
|
|
let n2 = run parsePositive("100") with {}
|
|
Console.print("Result: " + toString(n2))
|
|
let n3 = run safeDivide(100, 4) with {}
|
|
Console.print("Result: " + toString(n3))
|
|
}
|
|
|
|
let output = run main() with {}
|