Runnable chip programs. Run one with:
chip run examples/hello.chp
# or the shorthand
chip examples/hello.chpEvery single-file example here is exercised by a test (see examples_test.go at
the repo root), so its output is verified.
| File | Shows | Output |
|---|---|---|
| hello.chp | a minimal main |
Hello, chip |
| gcd.chp | recursion (Euclid's algorithm) | 21 |
| fibonacci.chp | recursion, define-before-use | 55 |
| mutual_recursion.chp | mutual recursion via a forward reference | 1 |
| forward_reference.chp | streaming: a statement calls a function defined later | streamed! |
| arrays.chp | slices, len, indexing, for |
4 then 20 |
packages/ is a multi-file program. Its entry file
packages/main.chp imports a local two-file package
(packages/geometry/) and the built-in math package, then
calls an exported function from each:
chip run examples/packages/main.chp # prints 12 then 21Imports resolve relative to the entry file's directory, so import "geometry"
finds packages/geometry/; import "math" resolves to the built-in package
(bundled in the binary). This example is verified by a test in cmd/chip.
See ARCHITECTURE.md for how chip streams these programs and loads packages.