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, var and const, and when to use each.
  • The primitive types — integers, floats, booleans and characters — and how literals get their types.
  • Printing values with Print, PrintLine and {} 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

LessonWhat you will learn
1.1Hello, Worldprint "Hello, World!", the minimal Rux application
1.2Commentexplain code with // and /* */ comments, which can nest
1.3Variablename a value with let, and let the compiler infer its type
1.4Mutabledeclare a binding with var so it can be reassigned
1.5Integerwhole numbers: signed and unsigned widths, int and uint
1.6Floatfractional numbers: float32, float64, and why 0.1 + 0.2 is not 0.3
1.7Booleantrue, false and the bool type
1.8Charactersingle characters, character literals and the char type
1.9Literalwrite numbers in other bases, with separators and suffixes
1.10Consolewrite to the console with Print and PrintLine, and fill {} placeholders
1.11Constname a value the compiler folds in, and see where it differs from let
1.12Convertconvert 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.