-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01_primitives.rzn
More file actions
168 lines (130 loc) · 4.6 KB
/
01_primitives.rzn
File metadata and controls
168 lines (130 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// ─────────────────────────────────────────────────────────────
// 01_primitives.rzn
// Covers: Primitives, Strings, Ranges
// Rules:
// := immutable | mut = mutable | const = constant
// shared = reference counted
// ─────────────────────────────────────────────────────────────
// ══════════════════════════════════════════════════════════════
// 1. PRIMITIVES
// ══════════════════════════════════════════════════════════════
// bool
is_active bool := true
has_error bool := false
mut is_logged_in bool = false
is_logged_in = true
// int
count int := 42
negative int := -100
hex_val int := 0xFF
binary int := 0b1010
octal int := 0o755
mut score int = 0
score = 99
const MAX_SCORE int = 100
const MIN_SCORE int = 0
// uint
index uint := 0u
size uint := 1024u
mut cursor uint = 0u
cursor = 512u
// float
pi float := 3.14159
price float := 99.99
gravity float := 9.81
mut temperature float = 36.6
temperature = 37.2
const PI float = 3.14159265358979
// str
name str := "Razen"
greeting str := "Hello, {name}!"
empty str := ""
mut username str = "guest"
username = "Alice"
const APP_NAME str = "Razen Lang"
const VERSION str = "1.0.0"
// bytes
raw_data bytes := bytes[0x48, 0x65, 0x6C, 0x6C, 0x6F]
buffer bytes := bytes[1024]
// void — no return value
act log(msg str) void {
println(msg)
}
act clear_screen() void {
println("\x1B[2J")
}
// Inferred types (obvious from value)
user_id := 1
ratio := 0.75
is_ready := true
lang := "Razen"
// ══════════════════════════════════════════════════════════════
// 2. STRINGS
// ══════════════════════════════════════════════════════════════
text := "Hello, Razen!"
user_name := "Alice"
age := 25
// Interpolation
msg := "Name: {user_name}, Age: {age}"
calc_msg := "Next year: {age + 1}"
// Raw strings (no escape processing)
file_path := r"C:\Users\razen\notes.txt"
pattern := r"\d+\.\d+"
// Multiline
multiline := "Line 1
Line 2
Line 3"
// Operations
length := text.len() // 11
is_empty := text.is_empty() // false
upper := text.to_upper_case() // "HELLO, RYX!"
lower := text.to_lower_case() // "hello, razen!"
trimmed := " spaces ".trim() // "spaces"
// Search
has_razen := text.contains("Razen") // true
starts_h := text.starts_with("Hello") // true
ends_excl := text.ends_with("!") // true
found_idx := text.find("Razen") // some(7)
// Replace & slice
replaced := text.replace("Razen", "World") // "Hello, World!"
slice := text[0..5] // "Hello"
// Split & join
parts := "a,b,c,d".split(",") // ["a","b","c","d"]
joined := parts.join(" - ") // "a - b - c - d"
// Parse
num_res := "42".parse_int() // result[int, ParseError]
flt_res := "3.14".parse_float() // result[float, ParseError]
// String builder
mut b := string_builder()
b.append("Hello")
b.append(", ")
b.append("Razen!")
final_str := b.to_string() // "Hello, Razen!"
// ══════════════════════════════════════════════════════════════
// 3. RANGES
// ══════════════════════════════════════════════════════════════
// Exclusive range (0 to 4)
loop i in 0..5 {
println(i)
}
// Inclusive range (0 to 5)
loop i in 0..=5 {
println(i)
}
// Step
loop i in (0..50).step(10) {
println(i) // 0, 10, 20, 30, 40
}
// Reverse
loop i in (0..5).reverse() {
println(i) // 4, 3, 2, 1, 0
}
// Char range
loop c in 'a'..='z' {
print(c) // a b c ... z
}
// Range as a value
my_range := 1..=5
loop n in my_range {
println(n * n) // 1, 4, 9, 16, 25
}