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
+40-18Lines changed: 40 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
import { Badge } from'rspress/theme';
1
+
import { Badge } from"rspress/theme";
2
2
3
3
# Basic Syntax
4
4
@@ -56,7 +56,6 @@ if len(global_variable) > 1 {
56
56
57
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 supports `f-strings` (formatted string literals, like Python's [f-string](https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings) but not identical) for string interpolation. F-strings provide a concise and readable way to embed expressions inside string literals. To create an f-string, prefix the string with `f` and use curly braces `{}` to include expressions.
180
+
181
+
```js
182
+
let name ="Alice";
183
+
let greeting = f"Hello, {name}!";
184
+
print(greeting); // Hello, Alice!
185
+
186
+
let x =10;
187
+
let y =5;
188
+
print(f"{x} + {y} = {x + y}"); // 10 + 5 = 15
189
+
print(f"{x} - {y} = {x - y}"); // 10 - 5 = 5
190
+
print(f"{x} * {y} = {x * y}"); // 10 * 5 = 50
191
+
print(f"{x} / {y} = {x / y}"); // 10 / 5 = 2
192
+
```
193
+
194
+
F-strings can contain any valid AIScript expression inside the curly braces. The expressions are evaluated at runtime and their results are converted to strings. This makes f-strings particularly useful for:
195
+
196
+
- String interpolation with variables
197
+
- Embedding arithmetic expressions
198
+
- Calling functions within strings
199
+
- Formatting complex data structures
200
+
177
201
## Control flow
178
202
179
203
```js
@@ -270,7 +294,6 @@ let d = a[:2]; // "AI"
270
294
271
295
```
272
296
273
-
274
297
## Loops
275
298
276
299
AIScript only has two keyword for loops: `for` and `while`.
@@ -320,7 +343,7 @@ let person = {
320
343
};
321
344
322
345
for (key, value) in person {
323
-
print("{key}: {value}");
346
+
print(f"{key}: {value}");
324
347
}
325
348
```
326
349
@@ -332,7 +355,6 @@ for i in 1..10 {
332
355
}
333
356
```
334
357
335
-
336
358
### Break and Continue
337
359
338
360
```js
@@ -359,4 +381,4 @@ AIScript provide a convenient way to access environment variables, the syntax is
0 commit comments