Skip to content

Hello, World!

A Novis program is a text file with the extension .nvs. Create a file called hello.nvs with these two lines:

<?nvs
echo "Hello, World!\n";
Output
Hello, World!

Run it:

Terminal window
nvs run hello.nvs

nvs run checks the program first. If there is an error, it prints the error and does not run the program.

Three things in this program:

  • <?nvs starts the code. Everything after it is code until the end of the file.
  • echo writes text. In a program you run in a terminal, the text goes to the terminal.
  • "\n" is a line break.

This program says hello to the name you give it. Save it as hello.nvs again:

<?nvs
// `Core\Cli::arguments()` returns the words after the file name on the command line.
var $arguments = Core\Cli::arguments();
// `??` gives "World" when the list is empty.
var $who = Core\Arr::first($arguments) ?? 'World';
echo Core\Str::format("Hello, %s!\n", $who);
Output
Hello, World!

Run it with a name after the file name:

Terminal window
nvs run hello.nvs Ada
Hello, Ada!

var declares a variable. Novis gets its type from the value. Core\Str::format puts values into a text. The compiler checks that the %s placeholders match the values.

Every function in the standard library is a method of a Core\ class. The Core reference lists all of them.

Next: A Tour of Novis builds on this program, one step at a time.