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

61 lines
1.1 KiB
Rexx

func sum(xs: []int): int {
var total = 0
for x in xs {
total += x
}
return total
}
func squares(n: int): []int {
var out: []int
for i in 0..n {
out.push(i * i)
}
return out
}
func largest(xs: []int): int {
var best = xs[0]
for x in xs {
if x > best {
best = x
}
}
return best
}
func main() {
var nums = [5, 3, 8, 1]
print(nums, nums.len())
print("sum:", sum(nums), "largest:", largest(nums))
nums.push(10)
nums[0] = 50
nums[1] += 7
print(nums)
print("popped", nums.pop(), "left", nums.len())
var sq = squares(6)
print(sq)
print(sq[1..4], sq[..2], sq[4..])
for i, x in sq {
if i % 2 == 0 {
print("sq[{i}] = {x}")
}
}
// an empty list needs a type
var empty: []string
print(empty, empty.len())
empty.push("a")
empty.push("b")
print(empty, "{empty.len()} items")
var floats: []float = [1, 2.5, 3]
print(floats)
var words = ["rex", "lang"]
print(words[0] + "-" + words[1], words[0].len())
}