Loading AI tools
Programming language optimized for artificial intelligence From Wikipedia, the free encyclopedia
Mojo is a programming language in the Python family that is currently under development.[3][4][5] It is available both in browsers via Jupyter notebooks,[5][6] and locally on Linux and macOS.[7][8] Mojo aims to combine the usability of a high-level programming language, specifically Python, with the performance of a system programming language such as C++, Rust, and Zig.[9] As of 2024[update], the Mojo compiler is proprietary software (closed source) with an open source standard library. Modular, the company behind Mojo, has stated an intent to eventually open source the Mojo language, as it matures.[10]
Paradigms |
|
---|---|
Family | Python |
Designed by | Chris Lattner[1] |
Developer | Modular Inc. |
First appeared | 2023 |
Preview release | 24.4[2]
/ May 24, 2024 |
Typing discipline | |
OS | Cross-platform: Linux, macOS |
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 builds on the Multi-Level Intermediate Representation (MLIR) compiler software framework instead of directly on the lower level LLVM compiler framework, as do many languages such as Julia, Swift, Clang, and Rust.[11][12] MLIR is a newer compiler framework that allows Mojo to exploit higher level compiler passes unavailable in LLVM alone, and allows Mojo to compile down and target more than only central processing units (CPUs), including producing code that can run on graphics processing units (GPUs), Tensor Processing Units (TPUs), application-specific integrated circuits (ASICs) and other accelerators. It can also often more effectively use certain types of CPU optimizations directly, like single instruction, multiple data (SIMD) with no direct intervention by a developer, as occurs in many other languages.[13][14] 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 artificial intelligence (AI).[15]
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.[16] Intention behind Mojo is to bridge the gap between Python’s ease of use and the fast performance required for cutting-edge AI applications.[17]
According to public change logs, Mojo development goes back to 2022.[18] In May of 2023, the first publicly testable version was made available online via a hosted playground.[19] By September 2023 Mojo was available for local download for Linux[20] and by October 2023 it was also made available for download on Apple's macOS.[21]
In March of 2024, Modular open sourced the Mojo standard library and started accepting community contributions under the Apache 2.0 license.[22][23]
Mojo was created for an easy transition from Python. The language has syntax similar to Python's, with inferred static typing,[24] and allows users to import Python modules.[25] It uses LLVM and MLIR as its compilation backend.[5][26][27] The language also intends to add a foreign function interface to call C/C++ and Python code. The language 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.[6]
The language also provides a borrow checker, an influence from Rust.[28] 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).[29]
The language is not open source, but it is planned to be made open source in the future.[30][31][32][33]
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
The Mojo SDK allows Mojo programmers to compile and execute Mojo source files locally from a command-line interface and currently supports Ubuntu and macOS.[34] 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.[35]
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.