This GitHub repository contains the example code presented along freeCodeCamp's YouTube video Mojo Programming Language – Full Course for Beginners. This introductory Mojo course was recorded by @elliotarlege.
Although there is an official GitHub repository linked in the YouTube video's description, as of this writing it does not contain all the code presented by Elliot. This was my motivation to create this repository and make it public.
Elliot sectioned his video into topics for which he presented live code examples. I've done my best to replicate Elliot's examples in each of the folders listed below, although you can expect some changes because Eliot makes changes quite frequently throughout the video, sometimes based on previous examples.
Below you will find the topics covered by Elliot in the order they were presented and a brief explanation of the topic or code contained in it:
Contains a hello world that includes importing Python libraries and reading from user input on the terminal.
Exactly as it says: a simple if
with else
and elif
usage.
Usage of for
and while
loops.
As of now, Mojo does not support arrays yet. This code shows how to import and use PythonObject
to simulate an array through an object.
The same function in Python and Mojo syntax, with some minor differences like, in Mojo, you should be explicit (i.e. Int8) whenever possible.
How to create classes, comparing Python and Mojo. Take a look at main.py
and main.mojo
.
Code shows how to import Python libraries, using numpy
as an example.
Exemplifying exceptions and errors with raises
, try
, except
and finally
while simulating the opening of a file.
Usage of inout
(mutable), borrowed
(immutable) and owned
(transfer ownership) for variables. This has more comments because these concepts may be kinda hard to grasp.
Only Python code. Usage of with
in Mojo has not been covered in the video tutorial.
An example showing how to create mojo packages to be used elsewhere. Plese refer to package-command.md
for instructions on how to use the mojo package <PACKAGE SOURCE FOLDER> -o <PACKAGE NAME>.mojopkg
.
SIMD
: Single Instruction Multiple Data, the coolest type ever: it's essentially a CPU instruction, for instance, if you have an array, you perform an operation through all of that array through SIMD.
In Python, you would have something like...
arr = [2, 4, 6, 8]
... and if you wanted to multiply all of its elements, you would have to loop trough it. With SIMD
you do everything in one operation.
Metaprogramming using decorators like @unroll
, but covered very superficially.
Assuming you have Mojo installed, go to each folder and run from the terminal:
mojo main.mojo
You can also mojo build [options] <path>
to create executable files if you really want to.
For the few Python files, it should be like python3 main.py
or python main.py
for earlier versions of Python.
Thank you Elliot Arledge and freeCodeCamp for the great Mojo video introduction.
Made with ❤️ by Carlos Eduardo Witte.