Part 1: Basics
Your first programs: printing, naming values, and the types those values have. By the end of this part you can write a program that prints a formatted report of numbers, characters and text — and you will have met the compiler's error messages often enough to read them without fear.
What you will learn
- The shape of every Rux program:
import,func Main() -> int, and the exit status. - Comments of all three kinds, including documentation comments.
- Naming values with
let,varandconst, and when to use each. - The primitive types — integers, floats, booleans and characters — and how literals get their types.
- Printing values with
Print,PrintLineand{}placeholders. - Converting between types with
as, and what happens when a value does not fit.
The primitive types at a glance
flowchart TB
v(["A value"]) --> num["Numbers"]
v --> b["Booleans<br/>bool (= bool8), bool16 … bool64"]
v --> c["Characters<br/>char (= char32), char8, char16, char64"]
num --> i["Integers"]
num --> f["Floats<br/>float64 (= float), float32"]
i --> s["Signed<br/>int8 … int512, int"]
i --> u["Unsigned<br/>uint8 … uint512, uint, byte"]Lessons
| Lesson | What you will learn | |
|---|---|---|
| 1.1 | Hello, World | print "Hello, World!", the minimal Rux application |
| 1.2 | Comment | explain code with // and /* */ comments, which can nest |
| 1.3 | Variable | name a value with let, and let the compiler infer its type |
| 1.4 | Mutable | declare a binding with var so it can be reassigned |
| 1.5 | Integer | whole numbers: signed and unsigned widths, int and uint |
| 1.6 | Float | fractional numbers: float32, float64, and why 0.1 + 0.2 is not 0.3 |
| 1.7 | Boolean | true, false and the bool type |
| 1.8 | Character | single characters, character literals and the char type |
| 1.9 | Literal | write numbers in other bases, with separators and suffixes |
| 1.10 | Console | write to the console with Print and PrintLine, and fill {} placeholders |
| 1.11 | Const | name a value the compiler folds in, and see where it differs from let |
| 1.12 | Convert | convert between numeric types with as, and see what a value that does not fit becomes |
Before you start
You need rux installed and the Examples repository cloned — Your first project covers both. Each lesson's package is in the repository's Basics/ folder:
cd Examples/Basics/Hello
rux run
After this part
Part 2: Operators combines the values you can now name into new ones, and Part 3: Control flow makes programs choose and repeat. After Part 3 you are ready for the first checkpoint projects, Thanks and FizzBuzz.
For the full rules behind this part, see Variables, Literals and the primitive types in the Rux Reference.