Guides

Intro to Mojo

This guide is in the early stages, feedback welcomed on Githubopen in new window

ChapterDescription
01: SetupIntroduction and how to use the Mojo playground
02: Basic TypesGet started with Mojo basic types and how to interact with Python

General

GuideDescription
Mojo Playground From VSCodeConnect VS Code to the Mojo Playground via the Jupyter Notebook extension

Builtins

ItemDescription
BoolThe primitive Bool scalar value used in Mojo
BuiltinListThe primitive ListLiteral class in Mojo
BuiltinSliceImplements slice.
ErrorImplements the Error class.
FloatLiteralFloating point literal type.
StringLiteralThis type represents a string literal. String literals are all null-terminated for compatibility with C APIs, but this is subject to change. String literals store their length as an integer, and this does not include the null terminator.
StringRefRepresent a constant reference to a string, i.e. a sequence of characters and a length, which need not be null terminated.
TupleTuple literal, consists of zero or more values separated by commas.

Decorators

ItemDescription
@always_inlineCauses body of the function to be copied directly into the body of the calling function in the final binary
@noncapturingMarks a closure as not capturing variables from the outer scope
@parameterCauses the function or if statement to run at compile time
@register_passableIndicates the values can be passed through registers
@valueGenerates initialization, move and copy boilerplate

Standard Library

ItemModuleDescription
AssertAssertPlace constraints on functions that are checked at compile time, and check conditions only in debug builds
BenchmarkBenchmarkPass in a closure that returns None as a parameter to benchmark its speed in nanoseconds
BufferBufferThe buffer doesn't own the underlying memory, it's a view over data that is owned by another object
NDBufferBufferA buffer that doesn't own the underlying memory, it allows you to represent an N-Dimensional shape both statically, and dynamically at runtime
DTypePointerPointerStore an address with a given DType, allowing you to allocate, load and modify data with convenient access to SIMD operations.
PointerPointer Store an address to any type, allowing you to allocate, load and modify single instances or arrays of the type on the heap
RandomRandomProvides functions for random numbers
SortSortSorts a DynamicVector[Int] inplace, in ascending order
StringStringMutable String with DynamicVector[Int8] as the underlying data type
TargetInfoTargetInfoFunctions related to determining host info such as OS, CPU, width etc.
TimeTimeMeasure elapsed time and make a thread sleep
DynamicVectorVectorDynamically allocated vector
InlinedFixedVectorVectorContains a statically known vector size, but can also grow dynamically at runtime
UnsafeFixedVectorVectorCan not be resized after initialization, but size can be runtime known

Benchmarks

Benchmarking various conversions of Python to Mojo

TitleDescription
Sudoku SolverSolving a Sudoku game as fast as possible