|
| 1 | +// SPDX-License-Identifier: MPL-2.0 |
| 2 | +// SPDX-FileCopyrightText: 2024-2026 hyperpolymath (Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>) |
| 3 | += Lesson 1: Hello, AffineScript |
| 4 | + |
| 5 | +The first stop in the tutorial series (lessons 1–10). For runnable, self-contained |
| 6 | +snippets covering the same early ground, see the |
| 7 | +link:../guides/warmup/[warm-up programs] (`*.affine` files you can `eval` directly). |
| 8 | + |
| 9 | +== Your first program |
| 10 | + |
| 11 | +[source,affinescript] |
| 12 | +---- |
| 13 | +fn main() -> Int { |
| 14 | + println("Hello, AffineScript!"); |
| 15 | + return 0; |
| 16 | +} |
| 17 | +---- |
| 18 | + |
| 19 | +A program is a set of declarations; `main` is the entry point. Functions use explicit |
| 20 | +`return`, and statements end with `;`. |
| 21 | + |
| 22 | +== Running it |
| 23 | + |
| 24 | +AffineScript type-, effect-, and borrow-checks ahead of time, then compiles to |
| 25 | +WebAssembly (it also has a tree-walking interpreter for quick runs): |
| 26 | + |
| 27 | +[source,sh] |
| 28 | +---- |
| 29 | +affinescript check hello.affine # static checks only (types, effects, borrows) |
| 30 | +affinescript eval hello.affine # check, then run via the interpreter |
| 31 | +affinescript compile hello.affine # check, then emit WebAssembly (-o out.wasm) |
| 32 | +---- |
| 33 | + |
| 34 | +Install by building from source — `dune build bin/main.exe` (entry point |
| 35 | +`_build/default/bin/main.exe`); prebuilt per-platform binaries are attached to tagged |
| 36 | +link:https://github.com/hyperpolymath/affinescript/releases[releases]. |
| 37 | + |
| 38 | +== What you'll learn |
| 39 | + |
| 40 | +[cols="1,4"] |
| 41 | +|=== |
| 42 | +| Lesson | Topic |
| 43 | + |
| 44 | +| link:lesson-02-functions.adoc[2] | Functions and ownership (`own` / `ref` / `mut`) |
| 45 | +| link:lesson-03-data.adoc[3] | Data: records, enums, tuples |
| 46 | +| link:lesson-04-patterns.adoc[4] | Pattern matching |
| 47 | +| link:lesson-05-types.adoc[5] | The type system |
| 48 | +| link:lesson-06-errors.adoc[6] | Errors and `Result` |
| 49 | +| link:lesson-07-effects.adoc[7] | Effects and handlers |
| 50 | +| link:lesson-08-generics.adoc[8] | Generics |
| 51 | +| link:lesson-09-modules.adoc[9] | Modules and imports |
| 52 | +| link:lesson-10-building.adoc[10] | Building a complete program |
| 53 | +|=== |
| 54 | + |
| 55 | +For the full language reference, see link:../../wiki/language-reference/[wiki/language-reference]; |
| 56 | +for authoritative feature status, link:../CAPABILITY-MATRIX.adoc[docs/CAPABILITY-MATRIX.adoc]. |
| 57 | + |
| 58 | +Next: link:lesson-02-functions.adoc[Lesson 2 — Functions and Ownership]. |
0 commit comments