Mojo REPL Environment
Overview
In this tutorial, we will learn about the Mojo REPL environment. REPL environments are great for quick testing, debugging, and exploring language features without compiling or running entire programs.
Mojo REPL Environment
The Mojo REPL environment is an interactive programming shell that allows code to be executed interactively in the terminal. REPL stands for Read–Eval–Print Loop (REPL).
Mojo REPL Session
To start a session, type mojo in your terminal and press Enter. It takes a single user input, executes it, and returns the result to the user.
$ mojo
Once you’re in the REPL, you can execute Mojo code interactively. The prompt 1> will be displayed indicating the first line of the session. At this prompt, we can start typing the command.
Example
For example, to print “Hello, World!”, you would type:
1> print(“Hello, World!”)
2.
Then press Enter twice to indicate the end of an expression. A blank line delimits expressions. This will execute the code statement, displaying the output on the screen.
To exit the REPL session, type the following :
> :quit
To get more help, type the following help command at the prompt:
> :mojo help
Let’s execute another simple arithmetic statement using the interactive shell. In this example, type the following simple arithmetic expression at the prompt:
1> print(7 + 9)
2.
This will evaluate the arithmetic expression and print the result 16 on the screen.
That’s it. By interacting with the tool, you can develop a deep understanding of the tool.
You can experiment with different expressions and see real-time results on the screen.
—
More information at Modular official website: