🐐 Snippets
This commit is contained in:
29
README.md
29
README.md
@@ -74,15 +74,19 @@ Single-quoted strings do **not** interpolate — `'{nomen}'` is the literal text
|
||||
|
||||
Strings support the same indexing and slicing syntax as arrays. Indexing is 1-based and returns a single-character string:
|
||||
|
||||

|
||||
|
||||
```
|
||||
"SALVTE"[I] @> "S"
|
||||
"SALVTE"[III] @> "L"
|
||||
> S
|
||||
> L
|
||||
```
|
||||
|
||||
Slicing uses `VSQVE` with inclusive bounds, returning a substring:
|
||||
|
||||

|
||||
|
||||
```
|
||||
"SALVTE"[II VSQVE IV] @> "ALV"
|
||||
> ALV
|
||||
```
|
||||
|
||||
Integer modulo is `RELIQVVM`: `VII RELIQVVM III` evaluates to `I`. Under the `FRACTIO` module it returns a fraction, so `IIIS RELIQVVM IS` is `S` (i.e. 1/2).
|
||||
@@ -138,10 +142,7 @@ Individual elements can be accessed by index using square brackets. Indexing is
|
||||
|
||||
Arrays are concatenated with `@`:
|
||||
|
||||
```
|
||||
DESIGNA x VT [I, II, III] @ [IV, V]
|
||||
DIC x
|
||||
```
|
||||

|
||||
|
||||
```
|
||||
> [I, II, III, IV, V]
|
||||
@@ -255,11 +256,7 @@ condition. Exit the loop with `ERVMPE` (or `REDI` from inside a function).
|
||||
|
||||
Variables can be unpacked in `PER` loops, similar to `DESIGNA` destructuring:
|
||||
|
||||
```
|
||||
PER a, b IN [[I, II], [III, IV]] FAC {
|
||||
DIC(a + b)
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
```
|
||||
> III
|
||||
@@ -270,13 +267,7 @@ PER a, b IN [[I, II], [III, IV]] FAC {
|
||||
|
||||
Errors can be caught using `TEMPTA` (temptare = to try) and `CAPE` (capere = to catch). The `CAPE` block binds the error message to a variable as a string.
|
||||
|
||||
```
|
||||
TEMPTA {
|
||||
DESIGNA x VT I / NVLLVS
|
||||
} CAPE error {
|
||||
DIC(error)
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
```
|
||||
> Division by zero
|
||||
|
||||
Reference in New Issue
Block a user