Coding
First of all there are no some special project file structure, config files or build system.
Single niva file is already can be a project.
Entry point and top level statements
main.niva
Now try niva run
By default, a file with this name is considered the entry point to the program.
You can specify a different entry point with niva run file.niva
(can be found in --help
)
All top-level code is executed from it. Top level expressions from other files are ignored, until you run the project from them.
This choice of entry point makes it convenient to experiment while writing modules, imagine that you are writing a GUI application, and each file contains a separate widget. You can write the code for constructing this widget at the top level of the file and run it to check how it looks separately from the entire project.
Now with niva run
only the code from main will be launched:
❯ niva run
slaps car
With niva run car.niva
only the top level code from car file ❯ niva run car.nivabrrr
And the last one niva run seller.niva
❯ niva run b.nivaHi, my name is Bob
No global state
This feature makes it impossible to create a global mutable state.
Since top-level variables are actually local to the current entry point:
Packages
The source files in niva do not have the same meaning as in ordinary languages, but they successfully pretend. In fact, niva uses the image approach (as in Smalltalk, Factor, Common Lisp), it's just that this image is built from scratch every time since it does not yet support serialization deserialization.
With that, it becomes possible to completely untie the file hierarchy from the package structure.
By default file name = package name and 1 file is 1 package.
But you can make several packages in one file: