← the guideThe Fluent Age

§ 02 — Eras · 2023

Mojo

Python’s syntax, systems performance — built for AI hardware

Left: era context, features, and the 101 hello. Right: 2 core concepts, 3 deeper 201 lessons, the factorial specimen, and where Mojo lives today — each column scrolls on its own.

creators
Modular (Chris Lattner again), 2023
status
young · bet in progress

The problem it solves

Python owns AI research but not its hardware. Mojo keeps the syntax and reclaims the performance — one language for lab and kernel.

The problem it carries

Young, single-vendor, and starting its ecosystem from zero; the bet is huge and unproven at scale.

Key features

fn and def
Two worlds in one language: a fast compiled fn, and a relaxed Python-like def.
struct
Compile-time data layout with no hidden overhead, ML-style.
static typing
Types where you want them, inferred where you do not.
GPU-native
Built for accelerators from the start, not bolted on afterwards.

101 — hello, world

Session one is the smallest program that still counts as speaking Mojo: what every tutorial prints first, in the dialect that mattered when the language arrived (2023).

the first program2023
fn main():
    print("Hello, world")

101First contact — hello world and 2 ideas that define how Mojo reads. 201 — 3 lessons on mechanisms you meet after the factorial specimen: the sharp edges practitioners actually use.

101 — core concepts

2 fragments, each naming a habit of mind in Mojo. Read the note, then the code — together they are the 101 in one sitting.

01 — fn vs def

fn is the strict, fast path — explicit types, no Python dynamism; def stays relaxed.

fn fact(n: Int) -> Int:
    var r = 1
    for i in range(1, n + 1):
        r *= i
    return r

02 — struct

Compile-time-bound structs for zero-cost data — ML’s answer to C.

struct Ship:
    var tons: Int

    fn heavy(self) -> Bool:
        return self.tons > 20

201 — going deeper

The 201 assumes you have read the 101 and the specimen. Each lesson is one mechanism — what it is for, how it looks in code, and the trap or payoff that makes Mojo distinctive at scale.

  1. fn, def and the type system
  2. structs and memory layout
  3. the AI stack

fn, def and the type system

fn is statically typed and compiled ahead of time; def keeps Python’s dynamism for exploration. Moving code from def to fn is how Mojo earns its speed.

fn compute(n: Int) -> Int:
    var total = 0
    for i in range(n):
        total += i
    return total

structs and memory layout

Structs are laid out at compile time and passed by value — no heap allocation unless you ask for it, unlike Python objects.

struct Ship:
    var tons: Int
    var name: String

    fn is_heavy(self) -> Bool:
        return self.tons > 20

the AI stack

SIMD and the compiler pipeline target accelerators directly, which is why a language with Python’s syntax can approach C++ speed on the right hardware.

The specimen — factorial

The fast path: fn and struct mark the zero-cost roads through a Python-shaped language — syntax borrowed wholesale, performance reclaimed.

the fast path2023
fn fact(n: Int) -> Int:
    var r = 1
    for i in range(1, n + 1):
        r *= i
    return r

Run it today

installcurl -ssL https://get.modular.com | bash -

runmojo run fact.mojo

Where it is now

AI kernels and Modular’s inference stack; the ecosystem is young, the performance claims are loud, and the bet is unproven at scale.