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

Hi all,

New update has been released for the book Mojo By Example. You can find the latest at: Mojo By Example: A Comprehensive Introduction to the Mojo Programming Language

I have updated the book with the new language changes up to 1.0.b2.

The change log is available in: https://ruhati.net/mojo/\_revision_history.html

Regards

Great work on this! These visuals are handy

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!

Thanks for the feedback!!

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.

Oops! Thanks for the catch! I missed fixing that one :face_with_peeking_eye: