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";Items: 3Total: 1525 centsRun it:
nvs run first-program.nvsIf you know PHP
Section titled “If you know PHP”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<?phpdoes not compile. - Every variable has a type, and the type never changes.
vartakes the type from the first value. - There are no casts. The
asoperator converts a value, and it throws an error if that is not possible. - There are no functions such as
intval,gettypeoris_int. Useasto convert a value andisto test its type. - Text from outside the program is
tainted.as stringon amixedvalue gives atainted string. - There are no global functions. Every built-in function is a method of a
Coreclass, such asCore\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.tomlsets which files, hosts and programs your code may use. A web request may do less than a program you start withnvs run.
How these pages are ordered
Section titled “How these pages are ordered”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 and don’t
Section titled “Do and don’t”- 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 theCoremethod instead.
