Files
rexlang/examples/basics/errors.rex
T
Your NameandClaude Opus 5.5 7cf9727bcd Rename the language from Dino to Rex
Files use .rex, the command is rex, and the crate, runtime prefixes,
docs, editor files and examples all use the new name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:51:23 +01:00

49 lines
902 B
Rexx

func parse_digit(c: string): (int, error) {
if c == "0" { return 0, nil }
if c == "1" { return 1, nil }
if c == "2" { return 2, nil }
return error("not a digit: {c}")
}
func add_digits(a: string, b: string): (int, error) {
var x = parse_digit(a)?
var y = parse_digit(b)?
return x + y, nil
}
func check(n: int): error {
if n < 0 {
return error("negative: {n}")
}
return nil
}
func run(): error {
check(5)?
print("5 is fine")
check(-3)?
print("never printed")
return nil
}
func main(): error {
var sum, err = add_digits("1", "2")
if err != nil {
print("unexpected:", err)
} else {
print("sum =", sum)
}
var _, bad = add_digits("1", "x")
if bad != nil {
print("failed:", bad)
}
var ok: error = nil
print("ok is", ok)
run()?
print("not reached")
return nil
}