Mojo is a compiled programming language designed by Modular for AI developers to combine the usability of Python with the performance of systems languages like C++. Mojo is being developed to become a full superset of Python over time, allowing existing Python code to run directly within Mojo programs while also offering new features for high-performance computing. This enables developers to create faster, more portable code for CPUs, GPUs, and other accelerators.

How Mojo is a superset of Python

Mojo’s design philosophy is Python-first, aiming to meet Python developers where they are by embracing the Python syntax and ecosystem. The “superset” concept for Mojo is similar to how TypeScript is a superset of JavaScript, adding advanced capabilities for performance-critical scenarios.

Key features and differences include:

Core components and goals

Meta Programming

Mojo’s metaprogramming features are integrated directly into the language, building upon Python’s familiar syntax to enable high-performance, compile-time code generation. The core of this system revolves around parameters, which are compile-time values, and the @parameter decorator.

How it works

Mojo Metaprogramming vs Circle Mojo’s compile-time metaprogramming uses a declarative parameterization system, while Sean Baxter’s Circle C++ employs an imperative, same-language reflection model with a built-in interpreter. Both approaches aim to provide powerful, zero-cost abstractions that surpass the capabilities and ergonomics of traditional C++ template metaprogramming, but they arrive at their destination from different philosophical standpoints.

Circle’s meta programming See also Circle

Sean Baxter’s Circle is an extension of C++17 that adds powerful imperative metaprogramming capabilities. Its system is built on three core pillars: an integrated interpreter, same-language reflection, and introspection keywords.

How it works

Similarities between Mojo and Circle

Differences between Mojo and Circle

Aspect Mojo Metaprogramming Circle C++ Metaprogramming
Core paradigm Declarative/Parametric: You declare parameters on functions and structs, and the compiler uses these for compile-time specialization and evaluation. Imperative/Reflective: You use the @meta keyword to explicitly execute code in a compile-time interpreter, which deposits new code into the AST.
Compiler integration Based on the MLIR compiler framework, which was designed from the ground up for this kind of parametric compilation. Mojo source is effectively syntactic sugar for MLIR. A custom C++ compiler built by Sean Baxter with an integrated C++ interpreter. It extends C++17 and its metaprogramming uses standard C++ syntax where possible.
Language syntax Blends Python-like syntax for readability with statically-typed features necessary for low-level systems programming. Retains C++ syntax but extends it with new keywords like @meta and built-in introspection operators.
Extensibility The MLIR foundation makes it easy to target various hardware backends. This is a core part of Modular’s mission for AI accelerators. The ability to execute arbitrary code at compile time allows for powerful data-driven code generation, such as reading configuration from JSON or Lua files.
Use case Aims to be a general-purpose language that specifically addresses the needs of high-performance AI and ML, combining Python’s ease of use with the performance of C++. Aims to be a comprehensive successor to C++ that tackles problems in systems programming and generic libraries, often through a lens of separating high-level goals from low-level implementation.