Files
rexlang/examples/basics/optionals.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

54 lines
905 B
Rexx

struct User {
name: string
age: int
}
func find(id: int): User? {
if id == 1 {
return User{name: "Ann", age: 30}
}
return nil
}
func first_even(xs: []int): int? {
for x in xs {
if x % 2 == 0 { return x }
}
return nil
}
func describe(id: int): string {
var u = find(id)
if u == nil {
return "nobody"
}
return "{u.name} is {u.age}"
}
func main() {
print(describe(1))
print(describe(2))
var n = first_even([1, 3, 4, 5])
if n != nil {
print("first even:", n + 1)
}
var m: int? = first_even([1, 3])
print("m is", m)
print("n is", n)
var count: int? = 5
if count != nil && count > 3 {
print("big count")
}
count = nil
if count == nil || count > 100 {
print("no count")
}
var list: []int? = nil
if list == nil {
print("no list")
}
}