Mojo (programming language)

Mojo is a programming language developed for the MLIR compiler framework that provides a unified programming framework for software development, especially in the field of artificial intelligence (AI).[2][3][4][5][6][7][8]

Mojo
Paradigm
FamilyPython
Designed byChris Lattner
DeveloperModular Inc.
First appeared2023 (2023)
Preview release
0.3.0[1]
Typing discipline
OSCross-platform
LicenseProprietary
Filename extensions.mojo, .🔥 (the fire emoji / the U+1F525 Unicode character)
Websitewww.modular.com/mojo
Influenced by
Python, Cython, C, C++, Rust, Swift, Julia, Zig, CUDA, MLIR, Clang

Designed to be a superset of the Python programming language,[7][9][10] the Mojo programming language is called by some as "Python++".[2][4][11][12][13][14][15]

Mojo was made available in browsers via Jupyter notebooks in May 2023[6][9], locally on Linux in September, 2023[16], and on macOS on October 19th, 2023.[17] An official Visual Studio Code extension is also available.[18]

Origin design and development

In 2022, the Modular company was founded by Chris Lattner, the original architect of the Swift programming language, and Tim Davis, an ML thought leader at Google.[19]

In September 2022, an initial build of Mojo was released internally by Modular Inc.[20] with advanced compilation features powered by the MLIR, the Multi-Level Intermediate Representation compiler framework.[6][21][22]

Its type system is hybrid (something between static and dynamic), given that the developer can opt-in for high performance static typing by choosing the keyword (between fn and def) to define their function.[23]

The companion Modular Inference Engine includes a compiler and runtime.[24]

Programming language advance

"Mojo is a new programming language, based on Python, which fixes Python’s performance and deployment problems."

The Mojo programming language aims to be fully compatible with the Project Jupyter ecosystem. It plans to add a borrow checker, an influence from Rust, and to add integration to transparently import Clang C/C++ modules and transparently generate a foreign function interface between C/C++ and Mojo. It can call existing Python 3.x code by reusing the CPython runtime.

Mojo is not yet fully source-compatible with Python 3, only providing a subset of its syntax so far in its early development (2023), 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. A struct in Mojo is similar to a Swift struct: they both support methods, fields, operator overloading, decorators for meta programming.[9]

Programming examples

Mojo's syntax and semantics exhibit similarities to other modern programming languages like Swift and Rust.

In Mojo, functions can be declared using both fn or def. The use of fn for function declaration, ensuring that the functions are strongly typed, is reminiscent of Rust's function declaration syntax.

Basic arithmetic operations in Mojo:

fn add(x: Int, y: Int) -> Int:
    return x + y

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.

Variable declaration and usage in Mojo:

fn main():
    let x = 1
    
    let y: Int
    y = 1

    var z = 0
    z += 1

See also

References

  1. "New Mojo update!". github.com. Modular. 2023-09-21. Retrieved 2023-09-26. We just released a new version of Mojo 🔥 (v0.3.0)
  2. "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.
  3. "Mojo 🔥 — the programming language for all AI developers". www.modular.com. Modular. 2023. Retrieved 2023-09-26. Mojo leverages MLIR, which enables Mojo developers to take advantage of vectors, threads, and AI hardware units.
  4. Hahn, Silke (2023-05-09). "Jenseits von Python: Mojo baut Brücke zwischen Python und C für Machine Learning". www.heise.de (in German). Heise Medien GmbH & Co. KG. Retrieved 2023-09-26. Eine neue Programmiersprache für Machine Learning, eine Art Python++?
  5. "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.
  6. Krill, Paul (4 May 2023). "Mojo language marries Python and MLIR for AI development". InfoWorld.
  7. Claburn, Thomas (5 May 2023). "Modular reveals Mojo, Python superset with C-level speed". The Register.
  8. Pandey, Mohit (3 May 2023). "This New Programming Language is Likely to Replace Python". Analytics India Magazine.
  9. Yegulalp, Serdar (7 June 2023). "A first look at the Mojo language". InfoWorld.
  10. "Welcome to Mojo 🔥". github.com. Modular. 2023. Retrieved 2023-09-26. Mojo is still young, but it is designed to become a superset of Python over time.
  11. Ramarao, Pramod (2023-09-07). "Mojo🔥 - It's finally here!". www.modular.com. Modular. Retrieved 2023-09-26. Mojo: a high performance 'Python++' language for compute
  12. Howard, Jeremy (2023-05-04). "Mojo may be the biggest programming language advance in decades". www.fast.ai. fast.ai. Retrieved 2023-09-26. Maybe it's better to say Mojo is Python++
  13. May, Eira (2023-09-25). "Like Python++ for AI developers". stackoverflow.blog. Stack Exchange, Inc. Retrieved 2023-09-26.
  14. Saplin, Maxim (2023-09-07). "Mojo🔥SDK has been released for Linux". dev.to. DEV Community. Retrieved 2023-09-26. From the creators of LLVM, Clang, and Swift. A better Python, Python++
  15. May, Eira (2023-09-22). "Mojo: The usability of Python with the performance of C". stackoverflow.blog. Stack Exchange, Inc. Retrieved 2023-09-26.
  16. Deutscher, Maria (7 September 2023). "Modular makes its AI-optimized Mojo programming language generally available". Silicon Angle. Retrieved 2023-09-11.
  17. "Mojo for Mac OS". Modular. Retrieved 2023-10-19.
  18. "Mojo for Visual Studio Code". marketplace.visualstudio.com. Microsoft. Retrieved 2023-09-26.
  19. Claburn, Thomas (2023-05-05). "Modular finds its Mojo, a Python superset with C-level speed". The Register. Retrieved 2023-08-08.
  20. "Mojo🔥 changelog".
  21. Lattner, Chris; Pienaar, Jacques (2019). MLIR Primer: A Compiler Infrastructure for the End of Moore's Law (Technical report). Retrieved 2022-09-30.
  22. 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].
  23. "Modular Docs - Mojo🔥 programming manual". docs.modular.com. Retrieved 2023-10-19.
  24. "Modular Inference Engine".
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.