Mojo (programming language)

From HandWiki
Short description: Artificial intelligence programming language
Mojo
Paradigm
FamilyPython
Designed byChris Lattner
DeveloperModular Inc.
First appeared2023; 1 year ago (2023)
Preview release
0.6.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[citation needed], C, C++, Rust, Swift, Zig

Mojo is a proprietary programming language under development.[2][3][4]

Mojo is available in browsers via Jupyter notebooks,[4][5] locally on Linux,[6] and on macOS.[7]

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, a former Google employee.[8]

In September 2022, an initial build of Mojo was released internally by Modular Inc.[9]

Mojo uses LLVM and MLIR as its compilation backend.[4][10][11]

Mojo uses inferred static typing.[12]

Mojo was created for easy transition from Python. The language has syntax similar to Python's, and allows users to import Python modules.[13]

Mojo is not open source, but it is planned to become open source in the future.[14]

Mojo plans to add a borrow checker, an influence from Rust.

Mojo plans to add a foreign function interface to call C/C++ and Python code.

Mojo 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.[5]

Mojo files use the .mojo or .🔥 file extension.[2]

Programming examples

In Mojo, functions can be declared using both fn (for performant functions) or def (for Python compatibility).[13]

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.[13]

Variable declaration and usage in Mojo:

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

    var z = 0
    z += 1

Development

The Mojo SDK allows Mojo programmers to compile and execute Mojo source files locally from the command line, and currently supports Ubuntu and macOS.[15] There is also a Mojo extension for Visual Studio Code, which provides code completion and tooltips.

See also

References

  1. ↑ "New Mojo update!". Modular. 2023-09-21. https://github.com/modularml/mojo/discussions/874. "We just released a new version of Mojo 🔥 (v0.3.0)" 
  2. ↑ 2.0 2.1 "Mojo🔥 programming manual". Modular. 2023. https://docs.modular.com/mojo/programming-manual.html. "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. ↑ "Why Mojo🔥 - A language for next-generation compiler technology". Modular. 2023. https://docs.modular.com/mojo/why-mojo.html. "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." 
  4. ↑ 4.0 4.1 4.2 Krill, Paul (4 May 2023). "Mojo language marries Python and MLIR for AI development" (in en). https://www.infoworld.com/article/3695588/mojo-language-marries-python-and-mlir-for-ai-development.html. 
  5. ↑ 5.0 5.1 Yegulalp, Serdar (7 June 2023). "A first look at the Mojo language" (in en). InfoWorld. https://www.infoworld.com/article/3697739/a-first-look-at-the-mojo-language.html. 
  6. ↑ Deutscher, Maria (7 September 2023). "Modular makes its AI-optimized Mojo programming language generally available" (in en). Silicon Angle. https://siliconangle.com/2023/09/07/modular-makes-ai-optimized-mojo-programming-language-generally-available/. 
  7. ↑ "Mojo for Mac OS". Modular. https://twitter.com/Modular_AI/status/1715024755093287042. 
  8. ↑ Claburn, Thomas (2023-05-05). "Modular finds its Mojo, a Python superset with C-level speed". The Register. https://www.theregister.com/2023/05/05/modular_struts_its_mojo_a/. Retrieved 2023-08-08. 
  9. ↑ "Mojo🔥 changelog". https://docs.modular.com/mojo/changelog.html#september-2022. 
  10. ↑ Template:Cite tech report
  11. ↑ 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].
  12. ↑ "Modular Docs - Mojo🔥 programming manual" (in en). https://docs.modular.com/mojo/programming-manual.html#parameterization-compile-time-metaprogramming. 
  13. ↑ 13.0 13.1 13.2 "Modular Docs - Mojo🔥 programming manual" (in en). https://docs.modular.com/mojo/programming-manual.html#python-integration. 
  14. ↑ Welcome to Mojo 🔥, Modular, 2023-10-31, https://github.com/modularml/mojo, retrieved 2023-10-31 
  15. ↑ "Modular Docs - Mojo🔥 roadmap & sharp edges" (in en). https://docs.modular.com/mojo/roadmap.html#mojo-sdk-known-issues. 

External links