Version: 1.1.0

Mojo quickstart

Install Mojo, run a program, and meet the syntax you will use immediately.

Install

Follow Install Mojo. Then check the compiler:

$ mojo --version

Hello

Save this as hello.mojo and run it with mojo run hello.mojo.

def main():
    print("Hello, world!")

A function and a variable

def area(w: Int, h: Int) -> Int:
    return w * h

def main():
    var w = 4
    print(area(w, 3))

var introduces a name. The type is fixed. def introduces a function.

A struct

@fieldwise_init
struct Point:
    var x: Int
    var y: Int

def main():
    var p = Point(2, 5)
    print(p.x + p.y)

Next

Build something larger in the Game of Life tutorial, or skim language basics.