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

51 lines
1.6 KiB
Rexx

import os
import math
import time
func count(path: string): (int, int, error) {
var text = os.read_file(path)?
var words = 0
var lines = 0
for line in text.lines() {
lines += 1
words += line.fields().len()
}
return lines, words, nil
}
func main() {
var csv = " alpha, beta ,gamma,, delta "
var parts = csv.split(",")
for p in parts { print("[" + p.trim() + "]") }
print(parts.len(), parts.join("|"))
print("Hello".upper(), "Hello".lower(), "a-b-c".replace("-", "+"), "ab".repeat(3))
print("hello".contains("ell"), "hello".starts_with("he"), "hello".ends_with("x"), "hello".index_of("l"), "hello".index_of("z"))
var n, err = "42".to_int()
print(n, err)
var bad, err2 = "4x2".to_int()
print(bad, err2)
var f, err3 = "2.5".to_float()
print(f * 2, err3)
print(math.sqrt(16), math.pow(2, 10), math.floor(2.7), math.round(2.5), math.PI)
print(math.min(3, 9), math.max(2.5, 1), math.abs(-7), math.abs(-2.5))
var small: u8 = 7
print(math.min(small, 200), math.max(small, 3))
var t0 = time.now()
time.sleep(0.01)
print(time.now() - t0 >= 0.01)
var err4 = os.write_file("/tmp/rex_std_test.txt", "one two\nthree\n\nfour five six\n")
print(err4)
var lines, words, e5 = count("/tmp/rex_std_test.txt")
print(lines, words, e5)
var l2, w2, e6 = count("/tmp/definitely/not/here.txt")
print(l2, w2, e6)
print(os.exists("/tmp/rex_std_test.txt"), os.exists("/nope"))
print(os.args.len(), os.env("HOME_NOPE_X") == nil)
var home = os.env("PATH")
if home != nil { print(home.len() > 0) }
os.exit(3)
}