🐐 Snippets

This commit is contained in:
2026-04-21 22:16:03 +02:00
parent 80d430970a
commit 5961884219
17 changed files with 21 additions and 27 deletions

View File

@@ -38,16 +38,11 @@ Variable can consist of lower-case letters, numbers, as well as `_`.
Multiple variables can be assigned at once by unpacking an array or multi-return function:
```
DEFINI pair (a, b) VT { REDI (a, b) }
DESIGNA x, y VT INVOCA pair (III, VII)
```
![Destructuring function](snippets/destructure_fn.png)
The number of targets must match the length of the array. This also works with array literals:
```
DESIGNA a, b, c VT [I, II, III]
```
![Destructuring array](snippets/destructure_array.png)
## Data types
### NVLLVS
@@ -69,12 +64,7 @@ Strings are concatenated with `&`:
Double-quoted strings support interpolation with `{expression}`:
```
DESIGNA nomen VT "Marcus"
DICE("Salve, {nomen}!") // → Salve, Marcus!
DICE("Sum: {III + IV}") // → Sum: VII
DICE("{nomen} has {V} cats") // → Marcus has V cats
```
![String interpolation](snippets/string_interp.png)
Any expression can appear inside `{}`. Values are coerced to strings the same way as with `&` (integers become Roman numerals, booleans become `VERITAS`/`FALSITAS`, etc.).
@@ -131,25 +121,15 @@ Individual elements can be accessed by index using square brackets. Indexing is
Dicts are key-value maps created with the `TABVLA` keyword and curly braces:
```
DESIGNA d VT TABVLA {"nomen" VT "Marcus", "aetas" VT XXV}
```
![Dict creation](snippets/dict_create.png)
Keys must be strings or integers. Values are accessed and assigned with square brackets:
```
DICE(d["nomen"]) // → Marcus
DESIGNA d["aetas"] VT XXVI // update existing key
DESIGNA d["novus"] VT I // insert new key
```
![Dict access](snippets/dict_access.png)
Iterating over a dict with `PER` loops over its keys:
```
PER k IN d FACE {
DICE(k)
}
```
![Dict iteration](snippets/dict_per.png)
`LONGITVDO(dict)` returns the number of entries. `CLAVES(dict)` returns the keys as an array.

BIN
snippets/aeternvm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -0,0 +1 @@
DESIGNA a, b, c VT [I, II, III]

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@@ -0,0 +1,2 @@
DEFINI pair (a, b) VT { REDI (a, b) }
DESIGNA x, y VT INVOCA pair (III, VII)

BIN
snippets/destructure_fn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1,3 @@
DICE(d["nomen"])
DESIGNA d["aetas"] VT XXVI
DESIGNA d["novus"] VT I

BIN
snippets/dict_access.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1 @@
DESIGNA d VT TABVLA {"nomen" VT "Marcus", "aetas" VT XXV}

BIN
snippets/dict_create.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

3
snippets/dict_per.cent Normal file
View File

@@ -0,0 +1,3 @@
PER k IN d FACE {
DICE(k)
}

BIN
snippets/dict_per.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -0,0 +1,4 @@
DESIGNA nomen VT "Marcus"
DICE("Salve, {nomen}!")
DICE("Sum: {III + IV}")
DICE("{nomen} has {V} cats")

BIN
snippets/string_interp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -9,8 +9,8 @@ contexts:
main:
- include: comments
- include: strings
- include: fractions
- include: keywords
- include: fractions
- include: numerals
- include: constants
- include: builtins