You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/language/basic.mdx
+39-25Lines changed: 39 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@ import { Badge } from 'rspress/theme';
2
2
3
3
# Basic Syntax
4
4
5
-
AIScript syntax is inspired by Python, JavaScript and Rust. If you familiar one of three languages, you can grasp the basic language syntax in 10 minutes.
5
+
AIScript syntax is inspired by Python, JavaScript and Rust. If you're familiar with any of these languages, you can grasp the basic language syntax in about 10 minutes.
6
6
7
7
## Comments
8
8
9
-
AIScript use`//`as the comment symbol.
9
+
AIScript uses`//`for comments.
10
10
11
11
```js
12
12
// This is a comment
@@ -17,7 +17,7 @@ print("Hello World");
17
17
18
18
## Semicolon
19
19
20
-
AIScript is semnicolon end language, that mean the`;` is required at the end of statements.
20
+
AIScript is a semicolon-terminated language, which means`;` is required at the end of statements.
21
21
22
22
```js
23
23
let a =1;
@@ -28,7 +28,7 @@ print(1 + 2);
28
28
29
29
## Variables
30
30
31
-
AIScript use`let` to define a variable, however type annotation is not support yet.
31
+
AIScript uses`let` to define variables. Type annotations are not supported yet.
32
32
33
33
```js
34
34
let name ="AIScript";
@@ -37,7 +37,7 @@ let age = 18;
37
37
// let flag: bool = false;
38
38
```
39
39
40
-
There are two kinds of variable: `global variable` and `local variable`. Any variable defined in the root scope is global variable, otherwise it is local scope variable.
40
+
There are two kinds of variables: `global variables` and `local variables`. Any variable defined in the root scope is a global variable; otherwise, it's a local scope variable.
41
41
42
42
```js
43
43
let global_variable ="abc";
@@ -47,14 +47,15 @@ if len(global_variable) > 1 {
47
47
print("I can access global variable:", global_variable); // print: I can access global variable: abc
48
48
}
49
49
50
-
//local variable is inaccessible outer of local scope,
51
-
//this print statement will raise error: Undefined variable 'local_variable'.
50
+
//Local variables are inaccessible outside of their local scope.
51
+
//This print statement will raise error: Undefined variable 'local_variable'.
52
52
// print(local_variable);
53
53
```
54
54
55
55
## Constants
56
56
57
-
Constants are declared with the `const` keyword, and they are immutable. Constants can only be declared once and must be initialized with a value, they cannot be reassigned.
57
+
Constants are declared with the `const` keyword and are immutable. Constants can only be declared once and must be initialized with a value; they cannot be reassigned.
AIScript doesn't support `i++`, `++i`, `i--` or `--i`!
158
+
AIScript doesn't support increment/decrement operators like `i++`, `++i`, `i--` or `--i`.
158
159
:::
159
160
160
161
## String
@@ -191,7 +192,7 @@ if age > 60 {
191
192
192
193
## Inline if
193
194
194
-
AIScript doesn't support `?` ternary operator like other languages, however you can use inline if syntax.
195
+
AIScript doesn't support the `?:` ternary operator like other languages, but you can use `inline if` syntax.
195
196
196
197
```js
197
198
let score =92;
@@ -201,11 +202,11 @@ print(result); // "A"
201
202
202
203
## Match
203
204
204
-
Use `match` to evaluate the expression whether meet the arms.
205
+
Use `match` to evaluate expressions against different patterns:
205
206
206
-
-`match` also support evaluate enum, learn more in [Enum chapter](/guide/language/enum-match)
207
+
-`match` also support evaluate enums, learn more in [Enum chapter](/guide/language/enum-match)
207
208
- Use `|` to combine multipe case in one arm
208
-
-`match` arm support `if guard`
209
+
-`match` arm support `if` guards
209
210
210
211
```js
211
212
let language ="AIScript";
@@ -221,9 +222,9 @@ match language {
221
222
222
223
## Functions
223
224
224
-
- Use `fn` keyword to define function, you can use `ai fn` to define [AI function](/guide/ai/function).
225
-
- Argument and return type annotation is recommend but can be optional.
226
-
- Use `|` to append error type after return type, see [Error handling](/guide/language/error-handling).
225
+
- Use `fn` keyword to define function; you can use `ai fn` to define [AI function](/guide/ai/function).
226
+
- Argument and return type annotations are recommend but optional.
227
+
- Use `|` to append error types after return type, see [Error handling](/guide/language/error-handling).
227
228
228
229
```js
229
230
fn add(a: int, b: int) -> int {
@@ -235,22 +236,22 @@ print(add(1, 2)); // 3
235
236
236
237
## Closures
237
238
238
-
Function is the first-class citizen in AIScript, hence you can return a function as closure. The biggest different closure compare to function is `closure will capture variable`.
239
+
Functions are first-class citizens in AIScript, so you can return a function as a closure. The key difference between closures and regular functions is that `closures capture variables` from their surrounding scope.
239
240
240
241
```js
241
-
fn add(a: int) -> fn {
242
-
fn _add(b: int) -> int {
242
+
fn add(a:int) {
243
+
fn add_inner(b: int) -> int {
243
244
return a + b;
244
245
}
245
246
246
-
return_add;
247
+
returnadd_inner;
247
248
}
248
249
249
250
let add5 =add(5);
250
251
print(add5(10)); // 15
251
252
```
252
253
253
-
Closure `_add` captured outer variable `a`.
254
+
Closure `add_inner` captures the outer variable `a`.
0 commit comments