Skip to content

Commit 5edf44a

Browse files
committed
Update README.md
1 parent f60006e commit 5edf44a

File tree

1 file changed

+58
-30
lines changed

1 file changed

+58
-30
lines changed

README.md

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ the expressiveness and ease-of-use of scripting languages with key design princi
88
- **Scripting Language**: Designed for automation, quick tasks, and rapid development
99
- **Memory Safety**: Explicit mutability control with `let` and `mut` keywords
1010
- **Static Typing**: Type annotations with inference capabilities for safer scripts
11-
- **Types and Methods**: Data structures with associated methods via `impl` blocks
12-
- **Control Flow**: Standard control structures (`if`/`else`, `while` loops)
11+
- **Types and Methods**: Data structures with associated methods defined using `fn TypeName.method_name(...)` syntax
12+
- **Control Flow**: Standard control structures (`if`/`else`, `while` loops) with `break` and `continue`
1313

1414
## Influences
1515

1616
- **Explicit Mutability**: Variables are immutable by default (`let`), mutable when specified (`let mut`)
17-
- **Impl Blocks**: Methods are defined separately from type definitions using `impl` blocks
17+
- **Type Methods**: Methods are defined separately from type definitions using `fn TypeName.method_name(...)` syntax
1818
- **Type Annotations**: Optional but explicit type annotations with `:` for safer scripts
1919
- **Arrow Syntax**: Function return types specified with `->`
2020
- **Memory Safety Focus**: Controlled mutability helps prevent common scripting errors
@@ -34,8 +34,14 @@ let opt_var: i32? = 5; // Optional type
3434
let mut opt_mut: f32? = 2.0; // Optional mutable type
3535
```
3636

37-
**Optional Types**: Types can be marked as optional using the `?` suffix. Optional types can hold a value or be null,
38-
providing safer handling of potentially absent values.
37+
**Optional Types**: Types can be marked as optional using the `?` suffix. Optional types can hold a value or be `null`,
38+
providing safer handling of potentially absent values. The `null` keyword is used to represent the absence of a value:
39+
40+
```text
41+
let opt_var: i32? = null; // Initialize with null
42+
let opt_var: i32? = 42; // Assign a value
43+
opt_var = null; // Assign null to optional type
44+
```
3945

4046
### Functions
4147

@@ -76,20 +82,20 @@ typedef Person {
7682

7783
### Methods
7884

79-
Implement methods for structs using `impl` blocks:
85+
Implement methods for structs using `fn TypeName.method_name(...)` syntax:
8086

8187
```text
82-
impl Point {
83-
fn distance(other: Point) -> f32 {
84-
let dx = self.x - other.x;
85-
let dy = self.y - other.y;
86-
return dx * dx + dy * dy;
87-
}
88-
89-
fn mut move(dx: f32, dy: f32) {
90-
self.x = self.x + dx;
91-
self.y = self.y + dy;
92-
}
88+
// Regular method
89+
fn Point.distance(other: Point) -> f32 {
90+
let dx = self.x - other.x;
91+
let dy = self.y - other.y;
92+
return dx * dx + dy * dy;
93+
}
94+
95+
// Mutable method (can modify the instance)
96+
fn mut Point.move_by(dx: f32, dy: f32) {
97+
self.x = self.x + dx;
98+
self.y = self.y + dy;
9399
}
94100
```
95101

@@ -126,6 +132,27 @@ let mut i = 0;
126132
while i < 10 {
127133
i = i + 1;
128134
}
135+
136+
// Break statement - exits the loop immediately
137+
let mut j = 0;
138+
while j < 10 {
139+
j = j + 1;
140+
if j == 5 {
141+
break; // Exit loop when j equals 5
142+
}
143+
}
144+
145+
// Continue statement - skips to next iteration
146+
let mut sum = 0;
147+
let mut k = 0;
148+
while k < 10 {
149+
k = k + 1;
150+
// Skip even numbers (using division/multiplication check)
151+
if k / 2 * 2 == k {
152+
continue; // Skip even numbers
153+
}
154+
sum = sum + k;
155+
}
129156
```
130157

131158
### Expressions
@@ -153,15 +180,13 @@ typedef Rectangle {
153180
height: f32;
154181
}
155182
156-
impl Rectangle {
157-
fn area() -> f32 {
158-
return self.width * self.height;
159-
}
160-
161-
fn mut scale(factor: f32) {
162-
self.width = self.width * factor;
163-
self.height = self.height * factor;
164-
}
183+
fn Rectangle.area() -> f32 {
184+
return self.width * self.height;
185+
}
186+
187+
fn mut Rectangle.scale(factor: f32) {
188+
self.width = self.width * factor;
189+
self.height = self.height * factor;
165190
}
166191
167192
fn main() {
@@ -174,9 +199,10 @@ fn main() {
174199
rect.scale(2.0);
175200
let scaled_area = rect.area();
176201
177-
// Example with optional types
202+
// Example with optional types and null
178203
let optional_width?: f32 = 15.0;
179204
let mut optional_height?: f32 = 8.0;
205+
let optional_result?: f32 = null; // Initialize with null
180206
}
181207
```
182208

@@ -318,11 +344,13 @@ cmake --build build --parallel
318344
Tea is currently in development. The core language features are implemented including:
319345

320346
- ✅ Variable declarations and assignments
321-
- ✅ Optional types with `?` syntax
347+
- ✅ Optional types with `?` syntax and `null` values
322348
- ✅ Function definitions and calls
349+
- ✅ Mutable functions with `fn mut` syntax
323350
- ✅ Struct definitions and instantiation
324-
- ✅ Method definitions with impl blocks
325-
- ✅ Control flow statements
351+
- ✅ Method definitions using `fn TypeName.method_name(...)` syntax
352+
- ✅ Control flow statements (`if`/`else`, `while` loops)
353+
- ✅ Loop control (`break` and `continue` statements)
326354
- ✅ Expression evaluation
327355
- ✅ Type system foundations
328356
- ✅ Native function binding

0 commit comments

Comments
 (0)