Mojo (programming language): Difference between revisions

Content deleted Content added
m {{multiref2|}}
m Replaced 1 bare URLs by {{Cite web}}; Replaced "Archived copy" by actual titles
 
(11 intermediate revisions by 9 users not shown)
Line 13:
}}
| family = [[Python (programming language)|Python]]
| designer = [[Chris Lattner]]<ref>{{cite web |url=https://www.fastcompany.com/91033509/modular-most-innovative-companies-2024 |title=How Modular simplified AI software infrastructure |publisherwork=Fast Company |date=19 March 2024 |access-date=2024-08-19 |last1=Sullivan |first1=Mark }}</ref>
| developer = Modular Inc.
| latest release version =
| latest release date =
| latest preview version = 2425.41<ref name="">{{cite web|url=https://docs.modular.com/mojo/changelog|title=Mojo Changelog|date=13 February 2025 |publisher=Modular |access-date=20242025-0402-1413}}</ref>
| latest preview date = {{start date and age|20242025|0502|2413}}
| typing = {{cslist|
[[Affine type system|Affine]]|
Line 39:
| influenced =
}}
'''Mojo''' is a [[programming language]] in the [[Python (programming language)|Python]] family that is currently under development.<ref name="MojoProgrammingManual_(2023)">{{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.}}</ref><ref name="Modular-WhyMojo_(2023)">{{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.}}</ref><ref name="InfoWorld">{{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}}</ref> It is available both in browsers via [[Project Jupyter#Jupyter Notebook|Jupyter notebooks]],<ref name="InfoWorld"/><ref name="IWFirst">{{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}}</ref> and locally on [[Linux]] and [[macOS]].<ref>{{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}}</ref><ref name="macOS_(2023)">{{cite web |url=https://x.com/Modular/status/1715024755093287042 |title=Mojo for Mac OS |publisher=Modular |access-date=2023-10-19}}</ref> Mojo aims to combine the usability of a [[high-level programming language]], specifically [[Python (programming language)|Python]], with the performance of a [[system programming language]] such as [[C++]], [[Rust (programming language)|Rust]], and [[Zig (programming language)|Zig]].<ref>{{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}}</ref> {{As of|20242025|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.<ref name="opensource" />
 
Mojo builds on the Multi-Level Intermediate Representation ([[MLIR (software)|MLIR]]) compiler [[software framework]], instead of directly on the lower level [[LLVM]] compiler framework, as dolike many languages such as [[Julia (programming language)|Julia]], [[Swift (programming language)|Swift]], [[ClangC++]], and Rust.<ref>{{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}}</ref><ref>{{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}}</ref> 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]]s (CPUs), including producing code that can run on [[graphics processing unit]]s (GPUs), [[Tensor Processing Unit]]s (TPUs), [[application-specific integrated circuit]]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.<ref>{{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}}</ref><ref>{{Cite web| title=Mojo - A system programming language for heterogenous computing | url=https://llvm.org/devmtg/2023-10/slides/keynote/Mojo.pdf | archive-url=https://web.archive.org/web/20240528174826/https://llvm.org/devmtg/2023-10/slides/keynote/Mojo.pdf | archive-date=2024-05-28}}</ref> According to [[Jeremy Howard (entrepreneur)|Jeremy Howard]] of fast.ai, Mojo can be seen as "[[Syntactic sugar|syntax sugar]] for MLIR" and for that reason Mojo is well optimized for applications like [[artificial intelligence]] (AI).<ref>{{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}}</ref>
 
== Origin and development history ==
The Mojo programming language was created by Modular Inc, which was founded by [[Chris Lattner]], the original [[Software architect|architect]] of the [[Swift (programming language)|Swift]] programming language and [[LLVM]], and Tim Davis, a former [[Google]] employee.<ref name="claburn2023">{{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}}</ref> IntentionThe intention behind Mojo is to bridge the gap between [[Python (programming language)|Python]]’s ease of use and the fast performance required for cutting-edge AI applications.<ref>{{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 }}</ref>
 
According to public change logs, Mojo development goes back to 2022.<ref>{{cite web|url=https://docs.modular.com/mojo/changelog.html#september-2022|title=Mojo changelog|date=13 February 2025 }}</ref> In May of 2023, the first publicly testable version was made available online via a hosted playground.<ref>{{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}}</ref> By September 2023 Mojo was available for local download for Linux<ref>{{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}}</ref> and by October 2023 it was also made available for download on [[Apple Inc.|Apple's]] macOS.<ref>{{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}}</ref>
 
In March of 2024, Modular open sourced the Mojo standard library and started accepting community contributions under the Apache 2.0 license.<ref>{{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}}</ref><ref>{{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}}</ref>
 
== Features ==
Line 62:
Basic arithmetic operations in Mojo with a {{mono|def}} function:
 
<syntaxhighlight lang="Pythonmojo">
def sub(x, y):
"""A pythonic subtraction."""
Line 71:
and with an {{mono|fn}} function:
 
<syntaxhighlight lang="rustmojo">
fn add(x: Int, y: Int) -> Int:
"""A rustacean addition."""
Line 81:
 
Variable declaration and usage in Mojo:
<syntaxhighlight lang="rustmojo">
fn main():
let x = 1