Mojo is a
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
in the
Python family that is currently under development.
It is available both in browsers via
Jupyter notebooks,
and locally on
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
and
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
.
Mojo aims to combine the usability of a
high-level programming language
A high-level programming language is a programming language with strong Abstraction (computer science), abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be ea ...
, specifically
Python, with the performance of a
system programming language such as
C++,
Rust, and
Zig. , the Mojo
compiler
In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
is closed source with an
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
standard library
In computer programming, a standard library is the library (computing), library made available across Programming language implementation, implementations of a programming language. Often, a standard library is specified by its associated program ...
. Modular, the company behind Mojo, has stated an intent to eventually open source the Mojo language, as it matures.
Mojo builds on the Multi-Level Intermediate Representation (
MLIR) compiler
software framework
In computer programming, a software framework is a software abstraction that provides generic functionality which developers can extend with custom code to create applications. It establishes a standard foundation for building and deploying soft ...
, instead of directly on the lower level
LLVM
LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
compiler framework like many languages such as
Julia,
Swift
Swift or SWIFT most commonly refers to:
* SWIFT, an international organization facilitating transactions between banks
** SWIFT code
* Swift (programming language)
* Swift (bird), a family of birds
It may also refer to:
Organizations
* SWIF ...
,
Clang
Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
, and Rust. 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 unit
A central processing unit (CPU), also called a central processor, main processor, or just processor, is the primary Processor (computing), processor in a given computer. Its electronic circuitry executes Instruction (computing), instructions ...
s (CPUs), including producing code that can run on
graphics processing units (GPUs),
Tensor Processing Units (TPUs),
application-specific integrated circuit
An application-specific integrated circuit (ASIC ) is an integrated circuit (IC) chip customized for a particular use, rather than intended for general-purpose use, such as a chip designed to run in a digital voice recorder or a high-efficienc ...
s (ASICs) and other accelerators. It can also often more effectively use certain types of CPU optimizations directly, like
single instruction, multiple data (SIMD) with minor intervention by a developer, as occurs in many other languages. 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
Artificial intelligence (AI) is the capability of computer, computational systems to perform tasks typically associated with human intelligence, such as learning, reasoning, problem-solving, perception, and decision-making. It is a field of re ...
(AI).
Origin and development history
The Mojo programming language was created by Modular Inc, which was founded by
Chris Lattner
Christopher Arthur Lattner (born 1978) is an American software engineer and creator of LLVM, the Clang compiler, the Swift (programming language), Swift programming language and the MLIR (software), MLIR compiler infrastructure.
After his PhD ...
, the original
architect
An architect is a person who plans, designs, and oversees the construction of buildings. To practice architecture means to provide services in connection with the design of buildings and the space within the site surrounding the buildings that h ...
of the
Swift
Swift or SWIFT most commonly refers to:
* SWIFT, an international organization facilitating transactions between banks
** SWIFT code
* Swift (programming language)
* Swift (bird), a family of birds
It may also refer to:
Organizations
* SWIF ...
programming language and
LLVM
LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
, and Tim Davis, a former
Google
Google LLC (, ) is an American multinational corporation and technology company focusing on online advertising, search engine technology, cloud computing, computer software, quantum computing, e-commerce, consumer electronics, and artificial ...
employee.
The intention behind Mojo is to bridge the gap between
Python’s ease of use and the fast performance required for cutting-edge AI applications.
According to public change logs, Mojo development goes back to 2022. In May of 2023, the first publicly testable version was made available online via a hosted playground. By September 2023 Mojo was available for local download for Linux and by October 2023 it was also made available for download on
Apple's macOS.
In March of 2024, Modular open sourced the Mojo standard library and started accepting community contributions under the Apache 2.0 license.
Features
Mojo was created for an easy transition from Python. The language has syntax similar to Python's, with inferred static typing, and allows users to import Python
modules.
It uses
LLVM
LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
and
MLIR as its compilation backend.
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
In mathematics, a Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they a ...
of its
syntax
In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
, e.g. missing the keyword, list and dictionary comprehensions, and support for classes. Further, Mojo also adds features that enable performant low-level programming: for creating
typed,
compiled functions and "struct" for
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
-optimized alternatives to
classes. Mojo structs support
methods,
fields,
operator overloading, and
decorators.
The language also provides a
borrow checker, an influence from
Rust. Mojo 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).
The language is not open source, but it is planned to be made open source in the future.
Programming examples
In Mojo, functions can be declared using both (for performant functions) or (for Python compatibility).
Basic arithmetic operations in Mojo with a function:
def sub(x, y):
"""A pythonic subtraction."""
res = x - y
return res
and with an function:
fn add(x: Int, y: Int) -> Int:
"""A rustacean addition."""
let res: Int = x + y
return res
The manner in which Mojo employs and for mutable and immutable variable declarations respectively mirrors the syntax found in Swift. In Swift, is used for mutable variables, while is designated for constants or immutable variables.
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 a
command-line interface
A command-line interface (CLI) is a means of interacting with software via command (computing), commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user ...
and currently supports
Ubuntu
Ubuntu ( ) is a Linux distribution based on Debian and composed primarily of free and open-source software. Developed by the British company Canonical (company), Canonical and a community of contributors under a Meritocracy, meritocratic gover ...
and macOS. 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.
See also
*
List of programming languages for artificial intelligence
References
External links
*
Mojo manual*
All about mojo programming language*
ttps://codeconfessions.substack.com/p/mojo-the-future-of-ai-programming Mojo: The Future of AI Programming
{{Authority control
AI software
Articles with example Python (programming language) code
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