A Program That Does Nothing
Here is the smallest program in Nevalang that compiles. It absolutely does nothing, but by looking at it, you can learn a lot about Nevalang.
component Main(start any) (stop any) {
net { :start -> :stop }
}
Let’s break down what’s written here.
A Nevalang program consists of components that send messages to each other through ports but ports cannot be connected randomly. Each port has its own data type, and when we connect one port to another, the compiler checks if they are compatible. Otherwise, it throws an error.
It states that there is a “Main” component (every component has a name), with two ports - one for input - start
- and one for output - stop
. The data type of both ports is any
- a universal data type, saying “I am compatible with any types of data.”
Main (start any) (stop any)
Next, we see a block of curly braces {}
and inside another one with the keyword net
.
{
net { :start -> :stop }
}
Ports are the interface of a component, but in addition to the interface, a component also needs a body - code that describes what exactly the component does, what work it performs. In this case, the curly braces are the body, and net
is the network - the computational scheme of the component.
In Nevalang, programming is flow-based, and instead of controlling the flow of execution, as in conventional languages, we control the flow of data. We don’t call functions, don’t execute instructions; we just route messages from one place to another, thus creating a graph that describes how data flows through the program. That’s why such programming is called flow-based.
In this case, we see that data flows directly from the input port start
to the output port stop
.
:start -> :stop
In other words, our Main component does nothing. It just lets data pass through itself without having any impact on the external world. Essentially, it could be called a bypass, but in a Nevalang program, there must always be at least one Main
component (we’ll understand why later).
What’s Next?
What, think this program isn’t useful enough? Then let’s move on to the next chapter!