Update BazzBasic-AI-guide.txt
Browse filesAdded guide how to pass array to user-defined function as JSON string
- BazzBasic-AI-guide.txt +32 -2
BazzBasic-AI-guide.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
**Name:** BazzBasic-AI-guide.txt
|
| 3 |
**Description:** BazzBasic BASIC interpreter language reference for AI. Use BazzBasic to write, debug, or teach code.
|
| 4 |
**File extensions:*** ".bas"*, *".bb"*
|
| 5 |
-
**Version:** This guide is written for BazzBasic version 1.2 and is updated
|
| 6 |
**URL:** This guide is stored and updated at https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
|
| 7 |
# END METADATA
|
| 8 |
|
|
@@ -38,7 +38,7 @@
|
|
| 38 |
| Functions defined **before** they are called | Put at top or INCLUDE |
|
| 39 |
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
|
| 40 |
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
|
| 41 |
-
| Arrays **cannot** be passed to functions | Pass individual elements by value |
|
| 42 |
| Case-insensitive | `PRINT`, `print`, `Print` all work |
|
| 43 |
| `+` operator does both add and concatenate | `"Hi" + " " + name$` |
|
| 44 |
| Division always returns float | `10 / 3` → `3.333...` |
|
|
@@ -213,6 +213,7 @@ FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
|
|
| 213 |
- Parameters passed **by value**
|
| 214 |
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 215 |
- Supports recursion
|
|
|
|
| 216 |
- Use `INCLUDE` to load functions from separate files if many
|
| 217 |
|
| 218 |
---
|
|
@@ -418,6 +419,35 @@ SAVEJSON arr$, "file.json"
|
|
| 418 |
|
| 419 |
---
|
| 420 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
## Fast Trigonometry
|
| 422 |
|
| 423 |
~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
|
|
|
|
| 2 |
**Name:** BazzBasic-AI-guide.txt
|
| 3 |
**Description:** BazzBasic BASIC interpreter language reference for AI. Use BazzBasic to write, debug, or teach code.
|
| 4 |
**File extensions:*** ".bas"*, *".bb"*
|
| 5 |
+
**Version:** This guide is written for BazzBasic version 1.2 and is updated 10.04.26 (ddmmyy)
|
| 6 |
**URL:** This guide is stored and updated at https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
|
| 7 |
# END METADATA
|
| 8 |
|
|
|
|
| 38 |
| Functions defined **before** they are called | Put at top or INCLUDE |
|
| 39 |
| Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
|
| 40 |
| Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
|
| 41 |
+
| Arrays **cannot** be passed to functions directly | Pass individual elements by value, or serialize with `ASJSON` and deserialize inside with `ASARRAY` — see *Passing Arrays to Functions* section |
|
| 42 |
| Case-insensitive | `PRINT`, `print`, `Print` all work |
|
| 43 |
| `+` operator does both add and concatenate | `"Hi" + " " + name$` |
|
| 44 |
| Division always returns float | `10 / 3` → `3.333...` |
|
|
|
|
| 213 |
- Parameters passed **by value**
|
| 214 |
- Labels inside functions are local — GOTO/GOSUB cannot jump outside
|
| 215 |
- Supports recursion
|
| 216 |
+
- Arrays as parameters not allowed. Use ASJSON to make array as JSON-string to pass it.
|
| 217 |
- Use `INCLUDE` to load functions from separate files if many
|
| 218 |
|
| 219 |
---
|
|
|
|
| 419 |
|
| 420 |
---
|
| 421 |
|
| 422 |
+
## Passing Arrays to Functions
|
| 423 |
+
|
| 424 |
+
Arrays cannot be passed directly to `DEF FN` functions. The accepted workaround (v1.2+) is JSON serialization: convert the array to a JSON string with `ASJSON`, pass it as a string parameter, then deserialize inside the function with `ASARRAY`.
|
| 425 |
+
|
| 426 |
+
```basic
|
| 427 |
+
DEF FN ProcessPlayer$(data$)
|
| 428 |
+
DIM arr$
|
| 429 |
+
LET count$ = ASARRAY(arr$, data$)
|
| 430 |
+
RETURN arr$("name") + " score:" + arr$("score")
|
| 431 |
+
END DEF
|
| 432 |
+
|
| 433 |
+
[inits]
|
| 434 |
+
DIM player$
|
| 435 |
+
player$("name") = "Alice"
|
| 436 |
+
player$("score") = 9999
|
| 437 |
+
player$("address,city") = "New York"
|
| 438 |
+
|
| 439 |
+
[main]
|
| 440 |
+
LET json$ = ASJSON(player$)
|
| 441 |
+
PRINT FN ProcessPlayer$(json$)
|
| 442 |
+
END
|
| 443 |
+
```
|
| 444 |
+
|
| 445 |
+
- The function gets a full independent copy — changes do not affect the original array
|
| 446 |
+
- Nested keys work normally: `arr$("address,city")` etc.
|
| 447 |
+
- Overhead is comparable to manually copying an array
|
| 448 |
+
|
| 449 |
+
---
|
| 450 |
+
|
| 451 |
## Fast Trigonometry
|
| 452 |
|
| 453 |
~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
|