Tour · 2 of 18
Values and bindings
The program on the right counts boxes and prices them.
#Number literals
item_cents := +1200
box_count := 3+1200 is an i32. A plain literal such as 3 is a usize when
nothing else sets its type. That is why quantity starts at +0: as 0, it
would be a usize, and adding an i32 would not check.
#:= and let
let quantity = +0
quantity = quantity + i32(box_count):= names a value that cannot be reassigned. let declares a variable
that can be replaced as a whole.
#Conversions
let total: i64 = i64(item_cents) * i64(quantity)Number widths never change silently. You write each conversion, such as
i32(...) or i64(...), where it happens. Without i64(item_cents), the
product mixes i32 and i64 and does not check.
#Names in strings
println("$quantity items cost $total cents")$name puts one binding in a string without the braces.
Run it. Three boxes at 1200 cents make 3600, so it prints
3 items cost 3600 cents.
Try it: change let quantity = +0 to quantity := +0 and press Run.
Run: Ctrl+Enter · Pages: Alt+← Alt+→