Bindings
A binding gives a name to something: a value, or a computation that makes one. Everything you name in Nylon is a binding, whether it's a number, a piece of text or a function.
let makes a binding that never changes. Once it's set, the name means that value for as long as it exists:
let width = 6
let greeting = "hello"
var makes one you can set again:
var count = 0
count = count + 1
Reach for let first. A name that can't change is one you never have to check on, and the compiler refuses an
assignment to a let, so the mistake can't slip through.
Where bindings live
A binding can stand at the top of a file, as a member of a class, or inside a function or block. It's the same form in each place:
let limit = 10
class Counter {
var count = 0
}
let doubled(value: i32) {
let result = value * 2
return result
}
Declare before you use
A name has to be declared before it's used, so a file reads from top to bottom. Using one any earlier is a compile error:
let first = 1
let second = first + 1