🐐 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
|
||||
|
||||
2
snippets/array_concat.cent
Normal file
2
snippets/array_concat.cent
Normal file
@@ -0,0 +1,2 @@
|
||||
DESIGNA x VT [I, II, III] @ [IV, V]
|
||||
DIC(x)
|
||||
BIN
snippets/array_concat.png
Normal file
BIN
snippets/array_concat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
3
snippets/per_destructure.cent
Normal file
3
snippets/per_destructure.cent
Normal file
@@ -0,0 +1,3 @@
|
||||
PER a, b IN [[I, II], [III, IV]] FAC {
|
||||
DIC(a + b)
|
||||
}
|
||||
BIN
snippets/per_destructure.png
Normal file
BIN
snippets/per_destructure.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
2
snippets/string_index.cent
Normal file
2
snippets/string_index.cent
Normal file
@@ -0,0 +1,2 @@
|
||||
DIC("SALVTE"[I])
|
||||
DIC("SALVTE"[III])
|
||||
BIN
snippets/string_index.png
Normal file
BIN
snippets/string_index.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
1
snippets/string_slice.cent
Normal file
1
snippets/string_slice.cent
Normal file
@@ -0,0 +1 @@
|
||||
DIC("SALVTE"[II VSQVE IV])
|
||||
BIN
snippets/string_slice.png
Normal file
BIN
snippets/string_slice.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
5
snippets/tempta_cape.cent
Normal file
5
snippets/tempta_cape.cent
Normal file
@@ -0,0 +1,5 @@
|
||||
TEMPTA {
|
||||
DESIGNA x VT I / NVLLVS
|
||||
} CAPE error {
|
||||
DIC(error)
|
||||
}
|
||||
BIN
snippets/tempta_cape.png
Normal file
BIN
snippets/tempta_cape.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user