Skip to content

Commit f529571

Browse files
committed
Add builtin functions docs
1 parent aa56b78 commit f529571

File tree

10 files changed

+696
-2
lines changed

10 files changed

+696
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Rspress website
1+
# AIScript website
2+
3+
[https://aiscript.dev](https://aiscript.dev)
4+
![](docs/public/aiscript-social-image.png)
25

36
## Setup
47

docs/std/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"name": "overview",
55
"label": "Overview"
66
},
7+
{
8+
"type": "dir",
9+
"name": "builtin",
10+
"label": "Buitins"
11+
},
712
{
813
"type": "dir",
914
"name": "db",

docs/std/builtin/_meta.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"type": "file",
4+
"name": "functions",
5+
"label": "Functions"
6+
},
7+
{
8+
"type": "file",
9+
"name": "string",
10+
"label": "String"
11+
},
12+
{
13+
"type": "file",
14+
"name": "response",
15+
"label": "Response"
16+
}
17+
]

docs/std/builtin/functions.md

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
# Built-in Functions
2+
3+
This document provides an overview of the built-in functions available in the AIScript VM.
4+
5+
## abs()
6+
7+
Returns the absolute value of a number.
8+
9+
**Parameters**:
10+
- A single number.
11+
12+
**Return Type**: `Number`
13+
14+
**Example**:
15+
```rust
16+
let result = abs(-5); // result is 5
17+
```
18+
19+
## all()
20+
21+
Returns `true` if all elements of the array are true.
22+
23+
**Parameters**:
24+
- An array of boolean values.
25+
26+
**Return Type**: `Boolean`
27+
28+
**Example**:
29+
```rust
30+
let result = all([true, true, false]); // result is false
31+
```
32+
33+
## any()
34+
35+
Returns `true` if any element of the array is true.
36+
37+
**Parameters**:
38+
- An array of boolean values.
39+
40+
**Return Type**: `Boolean`
41+
42+
**Example**:
43+
```rust
44+
let result = any([false, false, true]); // result is true
45+
```
46+
47+
## ascii()
48+
49+
Converts a value to its ASCII representation.
50+
51+
**Parameters**:
52+
- A single value.
53+
54+
**Return Type**: `String`
55+
56+
**Example**:
57+
```rust
58+
let result = ascii(65); // result is "A"
59+
```
60+
61+
## bin()
62+
63+
Converts a number to its binary representation.
64+
65+
**Parameters**:
66+
- A single number.
67+
68+
**Return Type**: `String`
69+
70+
**Example**:
71+
```rust
72+
let result = bin(5); // result is "101"
73+
```
74+
75+
## bool()
76+
77+
Converts a value to a boolean.
78+
79+
**Parameters**:
80+
- A single value.
81+
82+
**Return Type**: `Boolean`
83+
84+
**Example**:
85+
```rust
86+
let result = bool(0); // result is false
87+
```
88+
89+
## callable()
90+
91+
Checks if a value is callable.
92+
93+
**Parameters**:
94+
- A single value.
95+
96+
**Return Type**: `Boolean`
97+
98+
**Example**:
99+
```rust
100+
let result = callable(someFunction); // result is true
101+
```
102+
103+
## chr()
104+
105+
Converts an ASCII code to its character representation.
106+
107+
**Parameters**:
108+
- A single number representing an ASCII code.
109+
110+
**Return Type**: `String`
111+
112+
**Example**:
113+
```rust
114+
let result = chr(65); // result is "A"
115+
```
116+
117+
## filter()
118+
119+
Filters elements of an array based on a predicate function.
120+
121+
**Parameters**:
122+
- An array and a predicate function.
123+
124+
**Return Type**: `Array`
125+
126+
**Example**:
127+
```rust
128+
let result = filter([1, 2, 3], x => x > 1); // result is [2, 3]
129+
```
130+
131+
## float()
132+
133+
Converts a value to a floating-point number.
134+
135+
**Parameters**:
136+
- A single value.
137+
138+
**Return Type**: `Number`
139+
140+
**Example**:
141+
```rust
142+
let result = float("3.14"); // result is 3.14
143+
```
144+
145+
## format()
146+
147+
Formats a string using placeholders.
148+
149+
**Parameters**:
150+
- A format string and values to replace placeholders.
151+
152+
**Return Type**: `String`
153+
154+
**Example**:
155+
```rust
156+
let result = format("Hello, {}!", "world"); // result is "Hello, world!"
157+
```
158+
159+
## hex()
160+
161+
Converts a number to its hexadecimal representation.
162+
163+
**Parameters**:
164+
- A single number.
165+
166+
**Return Type**: `String`
167+
168+
**Example**:
169+
```rust
170+
let result = hex(255); // result is "ff"
171+
```
172+
173+
## input()
174+
175+
Reads a line of input from the user.
176+
177+
**Parameters**:
178+
- An optional prompt string.
179+
180+
**Return Type**: `String`
181+
182+
**Example**:
183+
```rust
184+
let name = input("Enter your name: ");
185+
```
186+
187+
## int()
188+
189+
Converts a value to an integer.
190+
191+
**Parameters**:
192+
- A single value.
193+
194+
**Return Type**: `Number`
195+
196+
**Example**:
197+
```rust
198+
let result = int("42"); // result is 42
199+
```
200+
201+
## len()
202+
203+
Returns the length of a string, array, or object.
204+
205+
**Parameters**:
206+
- A string, array, or object.
207+
208+
**Return Type**: `Number`
209+
210+
**Example**:
211+
```rust
212+
let length = len([1, 2, 3]); // length is 3
213+
```
214+
215+
## map()
216+
217+
Applies a function to each element of an array.
218+
219+
**Parameters**:
220+
- An array and a function.
221+
222+
**Return Type**: `Array`
223+
224+
**Example**:
225+
```rust
226+
let result = map([1, 2, 3], x => x * 2); // result is [2, 4, 6]
227+
```
228+
229+
## max()
230+
231+
Returns the maximum value from a list of numbers or an array.
232+
233+
**Parameters**:
234+
- A list of numbers or a single array.
235+
236+
**Return Type**: `Number`
237+
238+
**Example**:
239+
```rust
240+
let result = max(1, 2, 3); // result is 3
241+
```
242+
243+
## min()
244+
245+
Returns the minimum value from a list of numbers or an array.
246+
247+
**Parameters**:
248+
- A list of numbers or a single array.
249+
250+
**Return Type**: `Number`
251+
252+
**Example**:
253+
```rust
254+
let result = min(1, 2, 3); // result is 1
255+
```
256+
257+
## oct()
258+
259+
Converts a number to its octal representation.
260+
261+
**Parameters**:
262+
- A single number.
263+
264+
**Return Type**: `String`
265+
266+
**Example**:
267+
```rust
268+
let result = oct(8); // result is "10"
269+
```
270+
271+
## ord()
272+
273+
Returns the ASCII code of a character.
274+
275+
**Parameters**:
276+
- A single character.
277+
278+
**Return Type**: `Number`
279+
280+
**Example**:
281+
```rust
282+
let result = ord("A"); // result is 65
283+
```
284+
285+
## print()
286+
287+
Prints a value to the console.
288+
289+
**Parameters**:
290+
- A single value.
291+
292+
**Return Type**: `nil`
293+
294+
**Example**:
295+
```rust
296+
print("Hello, world!");
297+
```
298+
299+
## round()
300+
301+
Rounds a number to the nearest integer.
302+
303+
**Parameters**:
304+
- A single number.
305+
306+
**Return Type**: `Number`
307+
308+
**Example**:
309+
```rust
310+
let result = round(3.5); // result is 4
311+
```
312+
313+
## str()
314+
315+
Converts a value to a string.
316+
317+
**Parameters**:
318+
- A single value.
319+
320+
**Return Type**: `String`
321+
322+
**Example**:
323+
```rust
324+
let result = str(123); // result is "123"
325+
```
326+
327+
## sum()
328+
329+
Returns the sum of elements in an array.
330+
331+
**Parameters**:
332+
- An array of numbers.
333+
334+
**Return Type**: `Number`
335+
336+
**Example**:
337+
```rust
338+
let result = sum([1, 2, 3]); // result is 6
339+
```
340+
341+
## zip()
342+
343+
Combines multiple arrays into a single array of tuples.
344+
345+
**Parameters**:
346+
- Multiple arrays.
347+
348+
**Return Type**: `Array`
349+
350+
**Example**:
351+
```rust
352+
let result = zip([1, 2], [3, 4]); // result is [(1, 3), (2, 4)]
353+
```

0 commit comments

Comments
 (0)