Paradigm | |
---|---|
Family | Python |
Designed by | Chris Lattner |
Developer | Modular Inc. |
First appeared | 2023 |
Preview release | 0.6.0[1]
|
Typing discipline | |
OS | Cross-platform |
License | Apache License 2.0 |
Filename extensions | .mojo, .🔥 (the fire emoji / the U+1F525 Unicode character) |
Website | www |
Influenced by | |
Python, Cython[citation needed], C, C++, Rust, Swift, Zig |
Mojo is a proprietary programming language under development.[2][3][4]
Mojo is available in browsers via Jupyter notebooks,[4][5] locally on Linux,[6] and on macOS.[7]
In 2022, the Modular company was founded by Chris Lattner, the original architect of the Swift programming language, and Tim Davis, a former Google employee.[8]
In September 2022, an initial build of Mojo was released internally by Modular Inc.[9]
Mojo uses LLVM and MLIR as its compilation backend.[4][10][11]
Mojo uses inferred static typing.[12]
Mojo was created for easy transition from Python. The language has syntax similar to Python's, and allows users to import Python modules.[13]
Mojo is not open source, but it is planned to become open source in the future.[14]
Mojo plans to add a borrow checker, an influence from Rust.
Mojo plans to add a foreign function interface to call C/C++ and Python code.
Mojo is not source-compatible with Python 3, only providing a subset of its syntax, e.g. missing the global keyword, list and dictionary comprehensions, and support for classes. Further, Mojo also adds features that enable performant low-level programming: fn for creating typed, compiled functions and "struct" for memory-optimized alternatives to classes. Mojo structs support methods, fields, operator overloading, and decorators.[5]
Mojo files use the .mojo or .🔥 file extension.[2]
In Mojo, functions can be declared using both fn (for performant functions) or def (for Python compatibility).[13]
Basic arithmetic operations in Mojo:
fn add(x: Int, y: Int) -> Int:
return x + y
The manner in which Mojo employs var and let for mutable and immutable variable declarations respectively mirrors the syntax found in Swift. In Swift, var is used for mutable variables, while let is designated for constants or immutable variables.[13]
Variable declaration and usage in Mojo:
fn main():
let x = 1
let y: Int
y = 1
var z = 0
z += 1
The Mojo SDK allows Mojo programmers to compile and execute Mojo source files locally from the command line, and currently supports Ubuntu and macOS.[15] There is also a Mojo extension for Visual Studio Code, which provides code completion and tooltips.