mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
docs: the Polish technicians' and beginners' guides rewritten in natural Polish; vectors in every guide
- dla-technikow.md and dla-poczatkujacych.md written anew from the English, in plain Polish (no calques, the same words for the same things in every guide, addressing every reader alike) - the technicians' guides (en, pl): "Variants that hold values" moved to the enums section; the examples list has wordcount and simd - src/embedded.fch packs the runtime with its updated comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Psc42moPLwP43Cmb9oZqSR
This commit is contained in:
parent
8495bc718d
commit
06bfe940fa
5 changed files with 758 additions and 677 deletions
|
|
@ -1011,7 +1011,7 @@ Finch/
|
|||
├── std/ the standard library, in Finch: json, path, time, proc, fs, thread
|
||||
├── runtime/ finch_rt.c: the small runtime (text, arrays, maps, input, files)
|
||||
├── bootstrap/ build.sh, install.sh and the seeds (the compiler's own IR, one per system)
|
||||
├── examples/ hello, tour, types, structs, todo, guess, c_import, window, opengl, vulkan, raylib, llvm
|
||||
├── examples/ hello, tour, types, structs, todo, guess, wordcount, c_import, simd, window, opengl, vulkan, raylib, llvm
|
||||
├── tests/
|
||||
│ ├── run/ new/ programs + the exact output they must print (.out), input (.in)
|
||||
│ ├── fail/ new/fail/ programs that must fail, with the expected error in line 1
|
||||
|
|
@ -1025,35 +1025,12 @@ Finch/
|
|||
```
|
||||
|
||||
```sh
|
||||
tests/run.sh # programs, refusals, -g builds, a shared library, the language server
|
||||
tests/run.sh # programs, expected errors, -g builds, a shared library, the language server
|
||||
MEMCHECK=1 tests/run.sh # the same under valgrind: no leaks, no bad memory access
|
||||
tests/cross.sh windows # every test built for Windows and run with Wine
|
||||
tests/cross.sh arm64 # every test built for ARM64 Linux and run with QEMU
|
||||
```
|
||||
|
||||
### Variants that hold values
|
||||
|
||||
A variant can carry values. Make one with `Shape.Circle(2.0)`, take them out with `match`, which names them:
|
||||
|
||||
```c
|
||||
enum Shape {
|
||||
Circle(float)
|
||||
Rect(float, float)
|
||||
Point
|
||||
}
|
||||
|
||||
fn Shape.area() -> float {
|
||||
return match self {
|
||||
Circle(r) -> 3.14 * r * r
|
||||
Rect(w, h) -> w * h
|
||||
Point -> 0.0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`_` ignores a value. `match` must handle every variant (or end with `else`). Printing shows `Rect(2, 3.5)`. Such an enum is
|
||||
copied and freed like a struct; it can't be compared with `==` (match on it). Variants of these enums can't have numbers.
|
||||
|
||||
---
|
||||
|
||||
## 23. Enums and match
|
||||
|
|
@ -1100,6 +1077,29 @@ match word {
|
|||
handle **every variant** or end with `else` (the compiler says which are missing); any other match needs `else`.
|
||||
In an expression, every arm gives the same type.
|
||||
|
||||
### Variants that hold values
|
||||
|
||||
A variant can carry values. Make one with `Shape.Circle(2.0)`, take them out with `match`, which names them:
|
||||
|
||||
```c
|
||||
enum Shape {
|
||||
Circle(float)
|
||||
Rect(float, float)
|
||||
Point
|
||||
}
|
||||
|
||||
fn Shape.area() -> float {
|
||||
return match self {
|
||||
Circle(r) -> 3.14 * r * r
|
||||
Rect(w, h) -> w * h
|
||||
Point -> 0.0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`_` ignores a value. `match` must handle every variant (or end with `else`). Printing shows `Rect(2, 3.5)`. Such an enum is
|
||||
copied and freed like a struct; it can't be compared with `==` (match on it). Variants of these enums can't have numbers.
|
||||
|
||||
## 24. Generics
|
||||
|
||||
Write a function or a struct once for any type, with the type as a name in square brackets:
|
||||
|
|
|
|||
Loading…
Reference in a new issue