text stringlengths 0 721 |
|---|
| `REPLACE(s$, a$, b$)` | Replace a$ with b$ in s$ | |
| `SPLIT(arr$, s$, sep$)` | Split into array, returns count. Expects array is declared with DIM | |
| `SRAND(n)` | Random alphanumeric string of length n | |
| `STR(n)` | Number to string | |
| `VAL(s$)` | String to number | |
| `SHA256(s$)` | SHA256 hash (64-char hex) | |
| `BASE64ENCODE(s$)` / `BASE64DECODE(s$)` | Base64 encode/decode | |
--- |
## FSTRING — String Interpolation |
`FSTRING(template$)` substitutes `{{-name-}}` placeholders inside a template string with the value of variables, constants, or array elements. Preferred over long `+` concatenation chains. |
```basic |
LET name$ = "Krisu" |
LET LEVEL# = 5 |
PRINT FSTRING("Hello {{-name$-}}, level {{-LEVEL#-}}") |
' Output: Hello Krisu, level 5 |
``` |
The triple-character markers `{{-` and `-}}` are deliberately unusual so they will not collide with normal text. There is no escape syntax — literal `{{-...-}}` in the template is always parsed as a placeholder. |
### Placeholder forms |
| Form | Resolves to | |
|------|-------------| |
| `{{-var$-}}` | Value of variable `var$` | |
| `{{-CONST#-}}` | Value of constant `CONST#` | |
| `{{-arr$(0)-}}` | Array element at numeric index `0` | |
| `{{-arr$(i$)-}}` | Array element at index taken from variable `i$` | |
| `{{-arr$(KEY#)-}}` | Array element at index taken from constant `KEY#` | |
| `{{-arr$(name)-}}` | Array element at literal string key `"name"` (no quotes inside FSTRING) | |
| `{{-arr$(0, i$)-}}` | Multidimensional element, mixed literal and variable indices | |
### Index resolution rule (array access) |
For each comma-separated index, FSTRING looks at the last character: |
1. Ends with `$` or `#` → variable / constant lookup. Halts if undefined. |
2. Parses as a number (`0`, `1.5`, `-3`) → numeric index. `arr$(01)` and `arr$(1.0)` both resolve to key `1`. |
3. Otherwise → literal string key. This is what lets `{{-player$(name)-}}` read what was stored with `player$("name") = ...`. |
### Notes |
- Whitespace inside placeholders is trimmed: `{{- name$ -}}` ≡ `{{-name$-}}`. |
- Numbers auto-stringify — no `STR()` needed for numeric variables, constants, or array elements. |
- FSTRING returns a value; you must use it (`LET`, `PRINT`, pass to function). Calling it as a bare statement is an error. |
- Errors halt the program with a line-numbered message: undefined variable, missing closing `-}}`, empty placeholder `{{--}}`, malformed array access, uninitialized array element. |
### Not supported (intentional) |
No arithmetic, function calls, nested lookups, or quoted string literals inside placeholders. Pre-compute into a variable and reference that: |
```basic |
' ❌ WRONG |
PRINT FSTRING("Total: {{-a$ + 5-}}") |
PRINT FSTRING("Name: {{-UCASE(name$)-}}") |
PRINT FSTRING("{{-arr$(arr2$(0))-}}") |
' ✓ RIGHT |
LET total$ = a$ + 5 |
LET upper$ = UCASE(name$) |
LET k$ = arr2$(0) |
PRINT FSTRING("Total: {{-total$-}}, Name: {{-upper$-}}, Item: {{-arr$(k$)-}}") |
``` |
### Common AI mistakes with FSTRING |
```basic |
' ❌ WRONG ' ✓ CORRECT |
FSTRING("Hi {{name$}}") FSTRING("Hi {{-name$-}}") |
FSTRING("Hi {-name$-}") FSTRING("Hi {{-name$-}}") |
FSTRING("Hi {{-name-}}") ' array key FSTRING("Hi {{-name$-}}") |
FSTRING("Hi {{-name$-}}") ' as stmt LET s$ = FSTRING("Hi {{-name$-}}") |
``` |
Inside a placeholder, `name` (no suffix) is treated as a literal string key for an array lookup, **not** as a reference to variable `name$`. Always include the suffix. |
### Full working example |
```basic |
DIM player$ |
player$("name") = "Krisu" |
player$("class") = "Bass" |
player$("level") = 99 |
DIM grid$ |
grid$(0, 0) = "X" |
grid$(0, 1) = "O" |
grid$(1, 0) = "." |
grid$(1, 1) = "X" |
LET row$ = 1 |
LET PI# = 3.14 |
PRINT FSTRING("{{-player$(name)-}} the {{-player$(class)-}}, lvl {{-player$(level)-}}") |
PRINT FSTRING("Row {{-row$-}}: [{{-grid$(row$, 0)-}}{{-grid$(row$, 1)-}}]") |
PRINT FSTRING("Pi is roughly {{-PI#-}}") |
END |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.