Skip to content

Start here

A Novis program is a text file that ends in .nvs. You run it with nvs run. There is no build step and no main function. The statements in the file run from top to bottom.

<?nvs
// This program adds up a list of prices and prints the total.
array<int> $prices = [250, 1200, 75];
int $total = 0;
foreach ($prices as int $price) {
$total = $total + $price;
}
// `Core\Arr::count` returns the number of items in an array.
echo 'Items: ', Core\Arr::count($prices), "\n";
echo 'Total: ', $total, " cents\n";
Output
Items: 3
Total: 1525 cents

Run it:

Terminal window
nvs run first-program.nvs

The syntax of Novis comes from PHP, so much of it looks familiar. These are the things that are new or different:

  • The open tag is <?nvs. The tag <?php does not compile.
  • Every variable has a type, and the type never changes. var takes the type from the first value.
  • There are no casts. The as operator converts a value, and it throws an error if that is not possible.
  • There are no functions such as intval, gettype or is_int. Use as to convert a value and is to test its type.
  • Text from outside the program is tainted. as string on a mixed value gives a tainted string.
  • There are no global functions. Every built-in function is a method of a Core class, such as Core\Arr::count.
  • Options are one anonymous object at the end of a call: { order: Core\Arr::Order::Asc }.
  • The constructor is called constructor. There are no magic methods such as __toString.
  • A doc comment starts with ///.
  • nvs.toml sets which files, hosts and programs your code may use. A web request may do less than a program you start with nvs run.

Each page explains one part of the language. It shows the short way to write it first. When there is a longer way that does more, the page shows it under “Use this when”. Each page ends with a short list of things to do and things to avoid.

Start with Files and statements.

  • Do give every variable the type you mean. The compiler then finds mistakes for you.
  • Do look up a function in Reference when you need one.
  • Don’t look for a global function such as count(). Use the Core method instead.