Bitpath

Lesson 1 · Unit 01

Values

Bindings, shadowing and code that is all expressions

13 exercisesabout 3 min

What you practise

  • let and mut, shadowing, scalar types, expressions against statements, functions, if and loops as expressions

Try a question from this lesson

Pick one

In Python you can reassign any name. Which line does the Rust compiler reject?

Rust
let x = 5;
x = 6;
println!("{x}");

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Immutable unless you say so

let x = 5; binds a name that cannot be reassigned. Add mut to allow it: let mut x = 5;.

The default is the opposite of Python on purpose. When you read a plain let, you know the value never changes, and so does the compiler.

Rust
let total = 10;
let mut count = 0;
count += 1;
println!("{}", total + count);

Concept

One fixed type per value

Whole numbers are i32 unless you say otherwise. u8 holds 0 to 255 and usize is for lengths and indexes. Decimals are f64. There are also bool and char.

Rust never converts between them silently. as converts when you ask.

Rust
let big: i64 = 3_000_000_000;
let ratio = 7 as f64 / 2.0;
let letter = 'R';
println!("{big} {ratio} {letter}");

10 more exercises in the app

  • 2× fill the blanks
  • 4× type the answer
  • 2× multiple choice
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy