@Modular: Session 1 of Mojo 101 streamed yesterday, and the turnout was great. Our live chat was full of insightful questions. If…
Summary
Mojo 101 Session 1 recording is now available on YouTube, covering language fundamentals including project setup, hello world, and Mojo's compilation, static typing, and ownership model.
View Cached Full Text
Cached at: 07/10/26, 10:18 PM
Session 1 of Mojo 101 streamed yesterday, and the turnout was great. Our live chat was full of insightful questions.
If you missed it (or want to rewatch), the recording of Language Fundamentals is up now on YouTube: https://t.co/xkmcNOk0hm
TL;DR
Mojo 101 Session 1 covers setting up a Mojo project with Pixie, writing a “hello world” program, and understanding why Mojo’s compilation, static typing, and ownership model make it a powerful language for performance‑sensitive work.
Lesson Introduction and Goals
Michael Dun Connor, Developer Advocate at Modular, introduces the four‑part Mojo 101 series. The overall aim is to take learners from “hello world” to GPU programming, building on the existing Mojo GPU puzzles resource. By the end of the series, participants should be able to:
- Start parallel programming in Mojo on their own.
- Apply Mojo to their own domain problems.
- Contribute to the open‑source Mojo standard library and kernel projects.
Session 1 focuses on language fundamentals: creating a Mojo project, functions, control flow, and structs.
Creating a Mojo Project with Pixie
Pixie is used as the package manager. The steps are:
- Install Pixie (if not already installed) using the curl command from the Mojo quick‑start guide.
- Initialise a project:
This creates a directory with apixie init session_one cd session_onepixie.lockfile (dependencies initially empty). - Add the Mojo dependency:
This installs Mojo 1.0 beta 2 (the version used in the session).pixie add mojo - Enter the Pixie virtual environment:
Verify withpixie shellmojo --version– it should print “Mojo 1.0 beta 2”.
Hello World and Two Ways to Run
Create a file hello.mojo with the following content:
# This is a comment
def main():
print("hello world!")
The entry point must be a function named main.
Running the Code
Immediate compile‑and‑run:
mojo hello.mojo
Output: hello world!
Pre‑compile to a binary:
mojo build hello.mojo
This produces an executable named hello. Run it with ./hello. The compiled binary runs even outside the Pixie environment – demonstrating a key advantage of compiled languages.
Why Mojo? Compilation, Static Typing, and Ownership
Nate from the Mojo standard library team explains three core concepts that set Mojo apart.
Compiled vs. Interpreted Languages
Mojo is compiled, not interpreted like Python. The two‑step process (compile → binary) allows the compiler to optimise the code for the target hardware, resulting in very fast execution. The binary can be run without the original source or even the Mojo toolchain, as shown with the ./hello example.
Static Typing
Every variable and function parameter must have a known type at compile time. Mojo can infer the type from the initial value, or you can explicitly annotate it.
var x: Int = 42 # explicit type annotation
Because types are fixed, the compiler catches mismatches early. For instance, assigning a string to an integer variable produces a compile‑time error: “cannot implicitly convert ‘String’ to ‘Int’”. Similarly, a function that expects an Int argument cannot be called with a String.
Functions require explicit parameter and return types:
def add_one(x: Int) -> Int:
return x + 1
Omitting the return type leads to an error: “cannot implicitly convert ‘Int’ to ‘None’”. This strictness eliminates an entire class of runtime type errors common in dynamic languages.
Ownership and Memory Safety
Mojo uses a value‑semantics ownership model (similar to Rust). An example illustrates the difference:
var a = "hello"
var b = a # b is a *copy* of a
b += " world"
print(a) # outputs "hello"
print(b) # outputs "hello world"
Here a and b are separate instances. Modifying b does not affect a – a key distinction from languages where assignment creates a reference. This ownership system prevents accidental aliasing and makes memory management predictable.
Next Steps and QA
The session concluded with a brief open Q&A (team members answered live chat questions). Future sessions will follow the same structure: a topic overview, live coding, and a Q&A segment.
Similar Articles
@Modular: Week 2 of Mojo 101 goes live on Thursday. This week, we're deep diving on value ownership and metaprogramming on our li…
Modular announces Week 2 of Mojo 101, a free four-week live course teaching Mojo programming from the engineers who built it, covering value ownership and metaprogramming in the upcoming session.
@Modular: Mojo 101: From Syntax to GPU Programming [Session 1]
Modular is hosting a session called Mojo 101 covering syntax to GPU programming, aimed at teaching the Mojo language.
@Modular: Free 4-week Mojo course, taught by the team that built the language. See why Mojo is the ideal language for agentic dev…
Modular announces a free 4-week Mojo course taught by the Mojo team, covering language fundamentals to GPU programming, starting July 9th on YouTube.
@Modular: Mojo 1.0 beta is out! Now we want to hear from you. Share questions and start discussions in the Mojo 1.0 subcategory o…
Modular has released the beta version of Mojo 1.0 and is inviting the community to provide feedback and report issues on their forum and GitHub.
@Modular: Mojo Quest launches today! Mojo Quest is a browser-based game for learning Mojo syntax by closing engineering tickets f…
Mojo Quest is a browser-based game launched by Modular to help users learn Mojo syntax by completing engineering tickets for a fictional robotics company.