Mojo (programming language)

Last updated
Mojo
Paradigm
Family Python
Designed by Chris Lattner
Developer Modular Inc.
First appeared2023;1 year ago (2023)
Preview release
24.2.1 [1] / April 12, 2024;24 days ago (2024-04-12)
Typing discipline
OS Cross-platform
License Proprietary
Filename extensions .🔥 (the fire emoji/U+1F525 Unicode character), alternatively .mojo
Website www.modular.com/mojo
Influenced by
Python, Cython [ citation needed ], C, C++, Rust, Swift, Zig

Mojo is a programming language in the Python family that is currently under development. [2] [3] [4] It is available both in browsers via Jupyter notebooks, [4] [5] and locally on Linux and macOS. [6] [7] Mojo aims to combine the usability of higher level languages, specifically Python, with the performance of lower level ones. [8]

Contents

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

According to public change logs, Mojo development goes back to 2022. [10] In May of 2023, the first publicly testable version was made available online via a hosted playground. [11] By September 2023 Mojo was available for local download for Linux [12] and by October 2023 it was also made available for download on Apple's macOS. [13]

Features

Programming examples

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

Basic arithmetic operations in Mojo with a def function:

defsub(x,y):"""A pythonic subtraction."""res=x-yreturnres

and with an fn function:

fnadd(x: Int,y: Int)-> Int:     """A rustacean addition."""letres: Int=x+yreturnres

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

Variable declaration and usage in Mojo:

fnmain():     letx=1lety: Inty=1varz=0z+=1

Usage

The Mojo SDK allows Mojo programmers to compile and execute Mojo source files locally from the command line and currently supports Ubuntu and macOS. [21] 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. [22]

See also

Related Research Articles

CLU is a programming language created at the Massachusetts Institute of Technology (MIT) by Barbara Liskov and her students starting in 1973. While it did not find extensive use, it introduced many features that are used widely now, and is seen as a step in the development of object-oriented programming (OOP).

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.

<span class="mw-page-title-main">Python (programming language)</span> General-purpose programming language

Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.

In computer programming, the scope of a name binding is the part of a program where the name binding is valid; that is, where the name can be used to refer to the entity. In other parts of the program, the name may refer to a different entity, or to nothing at all. Scope helps prevent name collisions by allowing the same name to refer to different objects – as long as the names have separate scopes. The scope of a name binding is also known as the visibility of an entity, particularly in older or more technical literature—this is in relation to the referenced entity, not the referencing name.

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular for writing compilers, for programming language research, and for developing theorem provers.

In object-oriented (OO) and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change, but the object's state appears unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.

In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following:

In computer programming, a parameter or a formal argument is a special kind of variable used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are the values of the arguments with which the subroutine is going to be called/invoked. An ordered list of parameters is usually included in the definition of a subroutine, so that, each time the subroutine is called, its arguments for that call are evaluated, and the resulting values can be assigned to the corresponding parameters.

In computer programming, a default argument is an argument to a function that a programmer is not required to specify. In most programming languages, functions may take one or more arguments. Usually, each argument must be specified in full. Later languages allow the programmer to specify default arguments that always have a value, even if one is not specified when calling the function.

<span class="mw-page-title-main">LLVM</span> Compiler backend for multiple programming languages

LLVM is a set of compiler and toolchain technologies that can be used to develop a frontend for any programming language and a backend for any instruction set architecture. LLVM is designed around a language-independent intermediate representation (IR) that serves as a portable, high-level assembly language that can be optimized with a variety of transformations over multiple passes. The name LLVM originally stood for Low Level Virtual Machine, though the project has expanded and the name is no longer officially an initialism.

In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a parameter-passing strategy that defines the kind of value that is passed to the function for each parameter and whether to evaluate the parameters of a function call, and if so in what order. The notion of reduction strategy is distinct, although some authors conflate the two terms and the definition of each term is not widely agreed upon.

this, self, and Me are keywords used in some computer programming languages to refer to the object, class, or other entity which the currently running code is a part of. The entity referred to thus depends on the execution context. Different programming languages use these keywords in slightly different ways. In languages where a keyword like "this" is mandatory, the keyword is the only way to access data and methods stored in the current object. Where optional, these keywords can disambiguate variables and functions with the same name.

<span class="mw-page-title-main">Python syntax and semantics</span> Set of rules defining correctly structured programs

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. It supports multiple programming paradigms, including structured, object-oriented programming, and functional programming, and boasts a dynamic type system and automatic memory management.

In computer programming, an anonymous function is a function definition that is not bound to an identifier. Anonymous functions are often arguments being passed to higher-order functions or used for constructing the result of a higher-order function that needs to return a function. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function. Anonymous functions are ubiquitous in functional programming languages and other languages with first-class functions, where they fulfil the same role for the function type as literals do for other data types.

In certain computer programming languages, data types are classified as either value types or reference types, where reference types are always implicitly accessed via references, whereas value type variables directly contain the values themselves.

Christopher Arthur Lattner is an American computer scientist and creator of LLVM, the Clang compiler, the Swift programming language and the MLIR compiler infrastructure.

<span class="mw-page-title-main">Cython</span> Programming language

Cython is a superset of the programming language Python, which allows developers to write Python code that yields performance comparable to that of C.

In computer programming, a function, subprogram, procedure, method, routine or subroutine is a callable unit that has a well-defined behavior and can be invoked by other software units to exhibit that behavior.

Swift is a high-level general-purpose, multi-paradigm, compiled programming language created by Chris Lattner in 2010 for Apple Inc. and maintained by the open-source community. Swift compiles to machine code, as it is an LLVM-based compiler. Swift was first released in June 2014, and the Swift toolchain has shipped in Xcode since version 6, released in 2014.

References

  1. "Mojo Changelog". Modular. Retrieved 2024-04-14.
  2. 1 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. "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.
  4. 1 2 3 Krill, Paul (4 May 2023). "Mojo language marries Python and MLIR for AI development". InfoWorld.
  5. 1 2 Yegulalp, Serdar (7 June 2023). "A first look at the Mojo language". InfoWorld.
  6. Deutscher, Maria (7 September 2023). "Modular makes its AI-optimized Mojo programming language generally available". Silicon Angle. Retrieved 2023-09-11.
  7. "Mojo for Mac OS". Modular. Retrieved 2023-10-19.
  8. "Mojo 🔥: Programming language for all of AI". www.modular.com. Retrieved 2024-02-28.
  9. Claburn, Thomas (2023-05-05). "Modular finds its Mojo, a Python superset with C-level speed". The Register. Retrieved 2023-08-08.
  10. "Mojo🔥 changelog".
  11. "Modular: A unified, extensible platform to superpower your AI". www.modular.com. Retrieved 2024-04-14.
  12. "Modular: Mojo🔥 - It's finally here!". www.modular.com. Retrieved 2024-04-14.
  13. "Modular: Mojo🔥 is now available on Mac". www.modular.com. Retrieved 2024-04-14.
  14. Lattner, Chris; Pienaar, Jacques (2019). MLIR Primer: A Compiler Infrastructure for the End of Moore's Law (Technical report). Retrieved 2022-09-30.
  15. 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].
  16. "Modular Docs - Mojo🔥 programming manual". docs.modular.com. Retrieved 2023-10-19.
  17. 1 2 3 "Modular Docs - Mojo🔥 programming manual". docs.modular.com. Retrieved 2023-10-31.
  18. "Welcome to Mojo 🔥". GitHub . Modular. 2023-10-31. Retrieved 2023-10-31.
  19. "Ownership and borrowing | Modular Docs". Modular. Retrieved 2024-02-29.
  20. "Mojo🔥 programming manual". Modular. Archived from the original on 2023-06-11. Retrieved 2023-06-11. 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 def function use value semantics by default. Compared to Python, this is an important difference: A Mojo def function receives a copy of all arguments—it can modify arguments inside the function, but the changes are not visible outside the function.
  21. "Modular Docs - Mojo🔥 roadmap & sharp edges". docs.modular.com. Retrieved 2023-10-31.
  22. "llama2.mojo🔥 changelog". GitHub .