Book: Mojo By Example is now updated with changes corresponding to Mojo 1.0.b2

Hey! Nice project - I noticed a minor issue in your constants and variables section

The main benefit of a constant is that the compiler prevents any attempt to change the initially assigned value during the program execution.



def main():
    comptime counter: Int = 1
    print(counter)
    counter = counter + 3
    print(counter)

The explanation doesn’t feel quite right as the following compiles and runs without issue:

comptime counter: Int = 1


def main():
    # compiler prevents modification of compile time constants... or does it?
    print(counter)
    counter = counter + 3
    print(counter)
(mojo-by-example) ➜ mojo 03_constants_variables.mojo
1
4

Inside the function counter is implicitly declared as a new local variable shadowing the global constant… tricky!