Files
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

73 lines
1.3 KiB
Rexx

interface Shape {
area(): float
name(): string
}
interface Resizable {
scale(k: float)
}
struct Circle {
r: float
func area(): float { return 3.0 * r * r }
func name(): string { return "circle" }
func scale(k: float) { r = r * k }
}
struct Rect {
w, h: float
func area(): float { return w * h }
func name(): string { return "rect" }
}
enum Dot {
Small
Big
func area(): float { return 1.0 }
func name(): string { return "dot" }
}
func describe[T: Shape](s: T): string {
return "{s.name()} with area {s.area()}"
}
func total_area[T: Shape](shapes: []T): float {
var sum = 0.0
for s in shapes { sum += s.area() }
return sum
}
func grow[T: Resizable](s: T): T {
var copy = s
copy.scale(2.0)
return copy
}
struct Gallery[T: Shape] {
items: []T
func add(x: T) { items.push(x) }
func biggest(): float {
var best = 0.0
for it in items {
if it.area() > best { best = it.area() }
}
return best
}
}
func main() {
print(describe(Circle{2.0}))
print(describe(Rect{2.0, 5.0}))
print(describe(Dot.Big))
print(total_area([Circle{1.0}, Circle{2.0}]))
print(grow(Circle{1.5}))
var g = Gallery[Rect]{}
g.add(Rect{1.0, 2.0})
g.add(Rect{3.0, 4.0})
print(g.biggest())
}