This Week in Mojo 2023-07-14
Official Content
- New blog post titled: What's the difference between the AI Engine and Mojo?
Mojo Playground Update
⭐️ New
Mojo now has support for global variables! This enables
var
andlet
declaration at the top-level scope in Mojo files. Global variable initializers are run when code modules are loaded by the platform according to the order of dependencies between global variables, and their destructors are called in the reverse order.The Mojo programming manual is now written as a Jupyter notebook, and available in its entirety in the Mojo Playground
programming-manual.ipynb
. Previously,HelloMojo.ipynb
included most of the same material, but it was not up-to-date. We’ve also re-writtenHelloMojo.ipynb
to be much shorter and provide a more gentle first-user experience.Coroutine module documentation is now available. Coroutines form the basis of Mojo’s support for asynchronous execution. Calls to
async fn
can be stored into a Coroutine, from which they can be resumed, awaited upon, and have their results retrieved upon completion.
🦋 Changed
simd_bit_width
in the TargetInfo module has been renamed tosimdbitwidth
to better align withsimdwidthof
,bitwidthof
, etc.
🛠️ Fixed
The walrus operator now works in if/while statements without parentheses, such as
x := function():
Issue #428: The FloatLiteral and SIMD types now support conversion to Int via the
to_int
or__int__
method calls. The behavior matches that of Python, which rounds towards zero.
Mojo Team Answers
Global Variables REPL
Global variables were added to the language but they have not been wired into the REPL environment yet. The REPL environment layers extra features on the language to provide redefinition and top-level variables, and using global variables to enable the code you wrote has not occurred yet. Sorry for the confusion!