Mojo (programming language)
Paradigm | |
---|---|
Family | Python |
Designed by | Chris Lattner |
Developer | Modular Inc. |
First appeared | 2023 |
Preview release | 24.4 [1]
/ May 24, 2024 |
Typing discipline | |
OS | Cross-platform |
License | Proprietary |
Filename extensions | .🔥 (the fire emoji/U+1F525 Unicode character), alternatively .mojo |
Website | www |
Influenced by | |
Python, Cython[citation needed], C, C++, Rust, Swift, Zig |
Mojo is a programming language in the Python family that is currently under development.[2][3][4] It is available both in browsers via Jupyter notebooks,[4][5] and locally on Linux and macOS.[6][7] Mojo aims to combine the usability of higher level programming languages, specifically Python, with the performance of lower level programming languages like C++, Rust, and Zig.[8] The Mojo compiler is currently closed source with an open source standard library, although Modular, the company behind Mojo, has stated their intent to eventually open source the Mojo programming language itself as it matures.[9]
Mojo builds upon the MLIR compiler framework instead of directly on the lower level LLVM compiler framework that many languages like Julia, Swift, clang and Rust do.[10][11] MLIR is a newer compiler framework that allows Mojo to take advantage of higher level compiler passes not available in LLVM alone and allows Mojo to compile down and target more than just CPUs, including producing code that can run on GPUs, TPUs, ASICs and other accelerators. It can also often more effectively use certain types of CPU optimizations directly, like SIMD without direct intervention by the developer like in many other languages.[12][13] According to Jeremy Howard of fast.ai, Mojo can be seen as "syntax sugar for MLIR" and for that reason Mojo is well optimized for applications like AI.[14]
Origin and Development History
The Mojo programming language was created by Modular Inc, which was founded by Chris Lattner, the original architect of the Swift programming language and LLVM, and Tim Davis, a former Google employee.[15]
According to public change logs, Mojo development goes back to 2022.[16] In May of 2023, the first publicly testable version was made available online via a hosted playground.[17] By September 2023 Mojo was available for local download for Linux[18] and by October 2023 it was also made available for download on Apple's macOS. [19]
In March of 2024, Modular open sourced the Mojo standard library and started accepting community contributions under the Apache 2.0 license.[20][21]
Features
Mojo has the following features and characteristics:
- Mojo uses inferred static typing.[24]
- Mojo was created for easy transition from Python. The language has syntax similar to Python's, and allows users to import Python modules.[25]
- Mojo is not open source, but it is planned to become open source in the future.[26]
- Mojo has a borrow checker, an influence from Rust.[27]
- 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 def functions use value semantics by default (functions receive a copy of all arguments and any modifications are not visible outside the function), while Python functions use reference semantics (functions receive a reference on their arguments and any modification of a mutable argument inside the function is visible outside).[28]
- Mojo files use the .🔥 or .mojo file extension.[2]
Programming examples
In Mojo, functions can be declared using both fn (for performant functions) or def (for Python compatibility).[25]
Basic arithmetic operations in Mojo with a def function:
def sub(x, y):
"""A pythonic subtraction."""
res = x - y
return res
and with an fn function:
fn add(x: Int, y: Int) -> Int:
"""A rustacean addition."""
let res: Int = x + y
return res
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.[25]
Variable declaration and usage in Mojo:
fn main():
let x = 1
let y: Int
y = 1
var z = 0
z += 1
Usage
The Mojo SDK allows Mojo programmers to compile and execute Mojo source files locally from the command line and currently supports Ubuntu and macOS.[29] Additionally, there is a Mojo extension for Visual Studio Code which provides code completion and tooltips.
In January 2024, an inference model of LLaMA2 written in Mojo was released to the public.[30]
See also
References
- ^ "Mojo Changelog". Modular. Retrieved 2024-04-14.
- ^ a b "Mojo🔥 programming manual". docs.modular.com. Modular. 2023. Retrieved 2023-09-26.
Mojo is a programming language that is as easy to use as Python but with the performance of C++ and Rust. Furthermore, Mojo provides the ability to leverage the entire Python library ecosystem.
- ^ "Why Mojo🔥 - A language for next-generation compiler technology". docs.modular.com. Modular. 2023. Retrieved 2023-09-26.
While many other projects now use MLIR, Mojo is the first major language designed expressly for MLIR, which makes Mojo uniquely powerful when writing systems-level code for AI workloads.
- ^ a b c Krill, Paul (4 May 2023). "Mojo language marries Python and MLIR for AI development". InfoWorld.
- ^ a b Yegulalp, Serdar (7 June 2023). "A first look at the Mojo language". InfoWorld.
- ^ Deutscher, Maria (7 September 2023). "Modular makes its AI-optimized Mojo programming language generally available". Silicon Angle. Retrieved 2023-09-11.
- ^ "Mojo for Mac OS". Modular. Retrieved 2023-10-19.
- ^ "Mojo 🔥: Programming language for all of AI". www.modular.com. Retrieved 2024-02-28.
- ^ "Modular: The Next Big Step in Mojo🔥 Open Source". www.modular.com. Retrieved 2024-05-28.
- ^ Krill, Paul (2023-05-04). "Mojo language marries Python and MLIR for AI development". InfoWorld. Retrieved 2024-05-28.
- ^ "Should Julia use MLIR in the future?". Julia Programming Language. 2024-02-20. Retrieved 2024-05-28.
- ^ "Why Mojo🔥 | Modular Docs". docs.modular.com. Retrieved 2024-05-28.
- ^ https://llvm.org/devmtg/2023-10/slides/keynote/Mojo.pdf
- ^ Howard, Jeremy (2023-05-04). "fast.ai - Mojo may be the biggest programming language advance in decades". fast.ai. Retrieved 2024-05-28.
- ^ Claburn, Thomas (2023-05-05). "Modular finds its Mojo, a Python superset with C-level speed". The Register. Retrieved 2023-08-08.
- ^ "Mojo🔥 changelog".
- ^ "Modular: A unified, extensible platform to superpower your AI". www.modular.com. Retrieved 2024-04-14.
- ^ "Modular: Mojo🔥 - It's finally here!". www.modular.com. Retrieved 2024-04-14.
- ^ "Modular: Mojo🔥 is now available on Mac". www.modular.com. Retrieved 2024-04-14.
- ^ "Modular open-sources its Mojo AI programming language's core components". SiliconANGLE. 2024-03-28. Retrieved 2024-05-28.
- ^ "mojo/stdlib/README.md at nightly · modularml/mojo". GitHub. Retrieved 2024-05-28.
- ^ Lattner, Chris; Pienaar, Jacques (2019). MLIR Primer: A Compiler Infrastructure for the End of Moore's Law (Technical report). Retrieved 2022-09-30.
- ^ Lattner, Chris; Amini, Mehdi; Bondhugula, Uday; Cohen, Albert; Davis, Andy; Pienaar, Jacques; Riddle, River; Shpeisman, Tatiana; Vasilache, Nicolas; Zinenko, Oleksandr (2020-02-29). "MLIR: A Compiler Infrastructure for the End of Moore's Law". arXiv:2002.11054 [cs.PL].
- ^ "Modular Docs - Mojo🔥 programming manual". docs.modular.com. Retrieved 2023-10-19.
- ^ a b c "Modular Docs - Mojo🔥 programming manual". docs.modular.com. Retrieved 2023-10-31.
- ^ "Welcome to Mojo 🔥". GitHub. Modular. 2023-10-31. Retrieved 2023-10-31.
- ^ "Ownership and borrowing | Modular Docs". Modular. Retrieved 2024-02-29.
- ^ "Mojo🔥 programming manual". Modular. Archived from the original on 2023-06-11. Retrieved 2023-06-11.
All values passed into a Python def function use reference semantics. This means the function can modify mutable objects passed into it and those changes are visible outside the function. However, the behavior is sometimes surprising for the uninitiated, because you can change the object that an argument points to and that change is not visible outside the function. All values passed into a Mojo def function use value semantics by default. Compared to Python, this is an important difference: A Mojo def function receives a copy of all arguments—it can modify arguments inside the function, but the changes are not visible outside the function.
- ^ "Modular Docs - Mojo🔥 roadmap & sharp edges". docs.modular.com. Retrieved 2023-10-31.
- ^ "llama2.mojo🔥 changelog". GitHub.
External links
- AI software
- Cross-platform software
- High-level programming languages
- Multi-paradigm programming languages
- Notebook interface
- Programming languages
- Programming languages created in 2023
- Python (programming language)
- Text-oriented programming languages
- Python (programming language) implementations
- Software using the Apache license