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)
Yes, the shadowing is a bit tricky. I also realized that I didn’t provide information on shadowing in the book. I will include it in the next version. Thanks for the catch!
In Mojo, there are two ways to define a function. The first way is inspired by Rust and the second by Python. Both styles are equally first class in Mojo and both have their own use cases.
I think this section of the functions intro is a holdover from before fn was deprecated.