A Python superset, that also includes system programming features.
They released a local Mac installation this week (2023-10-18) and I tried it out on my laptop. The VSCode extension is still a little buggy.
New language constructs learnt include:
Ownership Syntax
| Syntax | Notes | Comments |
|---|---|---|
inout | Mutable | The reason it’s called this is because the mutations on the argument inside the function visible outside the function |
borrowed | Immutable reference | The default semantic, and doesn’t need to be declared. |
owned | Ownership | Rust uses this as the default semantic. |
Variable initialization
There are three ways to initialize a variable:
| Initialization Method | Syntax | Notes |
|---|---|---|
| Python-style | x = 1 | To be used in def-declared functions only |
Using let | let x = 1 | Denotes an immutable variable |
Using var | var x = 1 | Denotes a mutable variable |
Function Declaration
| Declaration Method | Notes |
|---|---|
def | Python-style. No strict enforcement of types and internal variable declarations |
fn | Requires Mojo-type hints to be specified, and internal variable declarations to use either let or var. |