Rename the Finch file extension from .fn to .fch

.fn is already used by other tools (e.g. Fennel). Modules are now looked up as name.fch;
a leftover name.fn gets a clear message telling you to rename it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nexoniarz 2026-10-08 19:27:42 +02:00
commit f897fb3140
92 changed files with 160 additions and 144 deletions

49
examples/structs.fch Normal file
View file

@ -0,0 +1,49 @@
// Structs, arrays of structs, and a linked list on the heap.
import "math.h"
struct Point {
float x
float y
}
struct Shape {
str name
[]Point corners
int color = 0xFF8800
}
struct Node {
int value
ptr[Node] next
}
fn perimeter(Shape s) -> float {
total := 0.0
for i in 0..s.corners.len {
a := s.corners[i]
b := s.corners[(i + 1) % s.corners.len]
dx := b.x - a.x
dy := b.y - a.y
total += sqrt(dx * dx + dy * dy)
}
return total
}
fn main() {
square := Shape(name: "square", corners: [Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)])
print(square.name, square.corners.len, "corners, perimeter", perimeter(square))
print(square)
// a linked list: new(...) puts a value on the heap, free(...) gives it back
ptr[Node] head = null
for i in 0..3 {
head = new(Node(value: i, next: head))
}
n := head
while n != null {
print("node", n.value)
next := n.next
free(n)
n = next
}
}