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

50 lines
925 B
Rexx

struct Counter {
n: int
func bump(): int {
n += 1
return n
}
}
struct Pair {
left: Counter
right: Counter
}
func bump_copy(c: Counter): int {
return c.bump()
}
func main() {
// assignment copies
var a = Counter{1}
var b = a
b.n = 100
print(a.n, b.n)
// passing to a function copies
print(bump_copy(a), a.n)
// methods change the variable they are called on
a.bump()
a.bump()
print(a.n)
// nested structs are copied as a whole
var p = Pair{Counter{10}, Counter{20}}
var q = p
q.left.bump()
p.right.bump()
p.right.bump()
print(p.left.n, p.right.n, q.left.n, q.right.n)
// reading before a later call in the same expression: the earlier read wins
var c = Counter{0}
print(c.n, c.bump(), c.n)
// constants can be read and used with non-mutating code
const k = Counter{7}
print(k.n)
}