Mojo (programming language)
{{Short description|Programming language optimized for artificial intelligence}}
{{Infobox programming language
| name = Mojo
| logo =
| logo size =
| logo alt =
| logo caption =
| paradigms = {{cslist|
imperative (primary)|
}}
| family = Python
| designer = Chris Lattner{{cite web |url=https://www.fastcompany.com/91033509/modular-most-innovative-companies-2024 |title=How Modular simplified AI software infrastructure |work=Fast Company |date=19 March 2024 |access-date=2024-08-19 |last1=Sullivan |first1=Mark }}
| developer = Modular Inc.
| latest release version =
| latest release date =
| latest preview version = 25.1{{cite web|url=https://docs.modular.com/mojo/changelog|title=Mojo Changelog|date=13 February 2025 |publisher=Modular |access-date=2025-02-13}}
| latest preview date = {{start date and age|2025|02|13}}
| typing = {{cslist|
duck|
}}
| operating system = Cross-platform: Linux, macOS
| license = Apache 2.0 with LLVM Exceptions{{Cite web |last=Modular Team |title=Modular: The Next Big Step in Mojoπ₯ Open Source |date=28 March 2024 |url=https://www.modular.com/blog/the-next-big-step-in-mojo-open-source |access-date=2024-11-09 |publisher=Modular |language=en |archive-date=2024-10-09 |archive-url=https://web.archive.org/web/20241009144412/https://www.modular.com/blog/the-next-big-step-in-mojo-open-source |url-status=live}}
| year = {{Start date and age|2023}}
| file ext = {{Mono|.π₯οΈσ ³σ σ σ σ ͺσ Ύσ σ σ »σ σ σ σ ’σ £σ σ σ £σ σ ₯σ σ σ ¦σ σ ’σ £σ σ σ σ σ ¦σ σ ’σ ’σ σ σ σ σ σ ₯σ £σ €σ σ £σ σ ©σ σ σ °σ σ Ώσ σ σ ©σ σ £σ ₯σ ’σ σ σ °σ σ σ €σ σ σ £σ ©σ £σ €σ σ σ σ σ σ ¦σ σ σ σ σ σ ’σ σ σ σ ’σ σ σ σ σ }} (the fire emoji/U+1F525 Unicode character), alternatively {{Mono|.mojo}}
| website = {{URL|www.modular.com/mojo}}
| wikibooks =
| implementations =
| dialects =
| influenced by = Python, Cython, C, C++, Rust, Swift, Zig, CUDA, MLIR{{multiref2|https://stackoverflow.blog/2023/10/02/no-surprises-on-any-system-q-and-a-with-loris-cro-of-zig/|https://www.fast.ai/posts/2023-05-03-mojo-launch.html|https://discourse.julialang.org/t/advantages-of-julia-vs-mojo/111614|https://www.infoq.com/news/2023/07/mojo-programming-language|https://www.theserverside.com/definition/What-is-Mojo-programming-language-and-what-is-it-used-for|https://www.opensourceforu.com/2024/04/programming-languages-for-ai-applications-and-why-mojo-is-among-the-best/}}
| influenced =
}}
Mojo is a programming language in the Python family that is currently under development.{{cite web |url=https://docs.modular.com/mojo/programming-manual.html |title=Mojo programming manual |date=2023 |website=docs.modular.com |publisher=Modular |access-date=2023-09-26 |quote=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.}}{{cite web |url=https://docs.modular.com/mojo/why-mojo.html |title=Why Mojo - A language for next-generation compiler technology |date=2023 |website=docs.modular.com |publisher=Modular |access-date=2023-09-26 |quote=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.}}{{cite web |last1=Krill |first1=Paul |title=Mojo language marries Python and MLIR for AI development |url=https://www.infoworld.com/article/3695588/mojo-language-marries-python-and-mlir-for-ai-development.html |website=InfoWorld |language=en |date=4 May 2023}} It is available both in browsers via Jupyter notebooks,{{cite news |last1=Yegulalp |first1=Serdar |title=A first look at the Mojo language |url=https://www.infoworld.com/article/3697739/a-first-look-at-the-mojo-language.html |work=InfoWorld |date=7 June 2023 |language=en}} and locally on Linux and macOS.{{cite news |last1=Deutscher |first1=Maria |title=Modular makes its AI-optimized Mojo programming language generally available |url=https://siliconangle.com/2023/09/07/modular-makes-ai-optimized-mojo-programming-language-generally-available/ |work=Silicon Angle |date=7 September 2023 |access-date=2023-09-11 |language=en}}{{cite web |url=https://x.com/Modular/status/1715024755093287042 |title=Mojo for Mac OS |publisher=Modular |access-date=2023-10-19}} 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.{{Cite web |title=Mojo: Programming language for all of AI |url=https://www.modular.com/max/mojo |access-date=2024-02-28 |website=Modular.com |language=en}} {{As of|2025|02}}, the Mojo compiler is 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.
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.{{Cite web |last1=Krill |first1=Paul |date=2023-05-04 |title=Mojo language marries Python and MLIR for AI development |url=https://www.infoworld.com/article/3695588/mojo-language-marries-python-and-mlir-for-ai-development.html |access-date=2024-05-28 |website=InfoWorld |language=en}}{{Cite web |date=2024-02-20 |title=Should Julia use MLIR in the future? |url=https://discourse.julialang.org/t/should-julia-use-mlir-in-the-future/110459 |access-date=2024-05-28 |website=Julia Programming Language |language=en}} 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 minor intervention by a developer, as occurs in many other languages.{{Cite web |title=Modular Docs: Why Mojo |url=https://docs.modular.com/mojo/why-mojo |access-date=2024-05-28 |website=docs.modular.com |language=en}}https://llvm.org/devmtg/2023-10/slides/keynote/Mojo.pdf 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).{{Cite web |last1=Howard |first1=Jeremy |author1-link=Jeremy Howard (entrepreneur) |date=2023-05-04 |title=fast.ai - Mojo may be the biggest programming language advance in decades |url=https://www.fast.ai/posts/2023-05-03-mojo-launch.html?ref=blef.fr |access-date=2024-05-28 |website=fast.ai |language=en}}
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.{{cite news |last1=Claburn |first1=Thomas |date=2023-05-05 |url=https://www.theregister.com/2023/05/05/modular_struts_its_mojo_a/ |title=Modular finds its Mojo, a Python superset with C-level speed |access-date=2023-08-08 |work=The Register}} Intention behind Mojo is to bridge the gap between Pythonβs ease of use and the fast performance required for cutting-edge AI applications.{{cite web | url=https://venturebeat.com/ai/mojo-rising-the-resurgence-of-ai-first-programming-languages/ | title=Mojo Rising: The resurgence of AI-first programming languages | date=21 May 2024 }}
According to public change logs, Mojo development goes back to 2022.{{cite web|url=https://docs.modular.com/mojo/changelog.html#september-2022|title=Mojo changelog|date=13 February 2025 }} In May of 2023, the first publicly testable version was made available online via a hosted playground.{{Cite web |title=A unified, extensible platform to superpower your AI |url=https://www.modular.com/blog/a-unified-extensible-platform-to-superpower-your-ai |access-date=2024-04-14 |website=Modular.com |language=en}} By September 2023 Mojo was available for local download for Linux{{Cite web |title=Mojo - It's finally here! |url=https://www.modular.com/blog/mojo-its-finally-here |access-date=2024-04-14 |website=Modular.com |language=en}} and by October 2023 it was also made available for download on Apple's macOS.{{Cite web |title=Mojo is now available on Mac |url=https://www.modular.com/blog/mojo-is-now-available-on-mac |access-date=2024-04-14 |website=Modular.com |language=en}}
In March of 2024, Modular open sourced the Mojo standard library and started accepting community contributions under the Apache 2.0 license.{{Cite web |date=2024-03-28 |title=Modular open-sources its Mojo AI programming language's core components |url=https://siliconangle.com/2024/03/28/modular-open-sources-mojo-ai-programming-languages-core-components/ |access-date=2024-05-28 |website=SiliconANGLE |language=en-US}}{{Cite web |title=mojo/stdlib/README.md at nightly Β· modularml/mojo |url=https://github.com/modularml/mojo/blob/nightly/stdlib/README.md |access-date=2024-05-28 |website=GitHub |language=en}}
Features
Mojo was created for an easy transition from Python. The language has syntax similar to Python's, with inferred static typing,{{Cite web |title=Modular Docs - Mojo programming manual |url=https://docs.modular.com/mojo/programming-manual.html#parameterization-compile-time-metaprogramming |access-date=2023-10-19 |website=docs.modular.com |language=en}} and allows users to import Python modules.{{Cite web |title=Modular Docs - Mojo programming manual |url=https://docs.modular.com/mojo/programming-manual.html#python-integration |access-date=2023-10-31 |website=docs.modular.com |language=en}} It uses LLVM and MLIR as its compilation backend.{{cite tech report |last1=Lattner |first1=Chris |title=MLIR Primer: A Compiler Infrastructure for the End of Moore's Law |date=2019 |url=https://research.google/pubs/pub48035/ |access-date=2022-09-30 |last2=Pienaar |first2=Jacques}}{{cite arXiv |last1=Lattner |first1=Chris |last2=Amini |first2=Mehdi |last3=Bondhugula |first3=Uday |last4=Cohen |first4=Albert |last5=Davis |first5=Andy |last6=Pienaar |first6=Jacques |last7=Riddle |first7=River |last8=Shpeisman |first8=Tatiana |last9=Vasilache |first9=Nicolas |last10=Zinenko |first10=Oleksandr |date=2020-02-29 |title=MLIR: A Compiler Infrastructure for the End of Moore's Law |class=cs.PL |eprint=2002.11054}} 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 {{mono|global}} keyword, list and dictionary comprehensions, and support for classes. Further, Mojo also adds features that enable performant low-level programming: {{mono|fn}} for creating typed, compiled functions and "struct" for memory-optimized alternatives to classes. Mojo structs support methods, fields, operator overloading, and decorators.
The language also provides a borrow checker, an influence from Rust.{{Cite web |title=Modular Docs: Ownership and borrowing |url=https://docs.modular.com/mojo/manual/values/ownership.html |access-date=2024-02-29 |publisher=Modular}} Mojo {{Mono|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).{{Cite web |title=Mojo programming manual |url=https://docs.modular.com/mojo/programming-manual.html |access-date=2023-06-11 |publisher=Modular |archive-url=https://web.archive.org/web/20230611225929/https://docs.modular.com/mojo/programming-manual.html |archive-date=2023-06-11 |quote=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 function use value semantics by default. Compared to Python, this is an important difference: A Mojo {{mono|def}} function receives a copy of all arguments: it can modify arguments inside the function, but the changes are not visible outside the function.}}
The language is not open source, but it is planned to be made open source in the future.{{Cite web |title=Open Source {{!}} Mojoπ₯ FAQ {{!}} Modular Docs |url=https://docs.modular.com/mojo/faq#open-source |access-date=2024-11-09 |website=docs.modular.com |language=en}}{{Cite web |title=Modular: Pricing |url=https://www.modular.com/pricing |access-date=2024-11-09 |website=www.modular.com |language=en}}{{Cite AV media |url=https://www.youtube.com/watch?v=tYujSI_aoqk&lc=Ugy-QQjJ4PYNJyrRc354AaABAg.A7Wv5n61lVtA7j_dibRIk7 |title=Comment from @modularinc |date=2024-08-22 |last=Modular |access-date=2024-11-09 |via=YouTube}}
Programming examples
In Mojo, functions can be declared using both {{mono|fn}} (for performant functions) or {{mono|def}} (for Python compatibility).
Basic arithmetic operations in Mojo with a {{mono|def}} function:
def sub(x, y):
"""A pythonic subtraction."""
res = x - y
return res
and with an {{mono|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 {{mono|var}} and {{mono|let}} for mutable and immutable variable declarations respectively mirrors the syntax found in Swift. In Swift, {{mono|var}} is used for mutable variables, while {{mono|let}} 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 and currently supports Ubuntu and macOS.{{Cite web |title=Modular Docs - Mojo roadmap & sharp edges |url=https://docs.modular.com/mojo/roadmap.html#mojo-sdk-known-issues |access-date=2023-10-31 |website=docs.modular.com |language=en}} 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.{{cite web|url=https://github.com/tairov/llama2.mojo|title=llama2.mojo changelog|website=GitHub}}
See also
References
{{Reflist}}
External links
- {{Official website|www.modular.com/mojo}}
- [https://docs.modular.com/mojo/manual/ Mojo manual]
- {{GitHub|modularml/mojo}}
- [https://virtualgyan.com/mojo-lang-the-new-programming-language/ All about mojo programming language]
- [https://www.fast.ai/posts/2023-05-03-mojo-launch.html Mojo may be the biggest programming language advance in decades]
- [https://codeconfessions.substack.com/p/mojo-the-future-of-ai-programming Mojo: The Future of AI Programming]
{{Programming languages}}
{{Statistical software}}
{{Numerical analysis software}}
{{Authority control}}
Category:Articles with example Python (programming language) code
Category:Cross-platform software
Category:High-level programming languages
Category:Multi-paradigm programming languages
Category:Programming languages
Category:Programming languages created in 2023
Category:Python (programming language)
Category:Text-oriented programming languages