What is Nock?

Nock is the programming language used to create Urbit. It is a low-level language that essentially creates a mathematical definition of computation.

Its syntax looks like this:

[2 [0 3] [0 2]]

Nock is a minimalist, deterministic, combinatorial language based on functions and expressions. Its simplicity allows it to be easily implemented on any platform, which is a desirable feature for a project like Urbit, which seeks to create an independent and enduring computational environment.

The Nock language was created this way to be a minimal and stable core that could serve as a foundation for building other layers of abstraction in the Urbit ecosystem (as we discussed in this article when talking about modularity).

By creating a low-level language with simple rules and easy implementation, Urbit developers ensure that the language is robust and can be ported to different hardware and software architectures without problems.

What is the relationship between Nock and Hoon?

Hoon is another programming language in the Urbit ecosystem, designed to be high-level and more programmer-friendly than Nock. Hoon is the main language used by developers to write code in Urbit. The Hoon compiler translates Hoon code into Nock expressions, which are then executed by the Nock virtual machine.

In other words, Nock is the language that commands Urbit, and Hoon is a more user-friendly way to create Nock.

In practice, if you want to create applications in Urbit, you don’t need to learn Nock, as Hoon is the language developers use in practice. In fact, the Arvo operating system is written in Hoon.

We can say that the relationship between Hoon and Nock is similar to the relationship between a high-level language and its respective bytecode or machine language. Hoon allows developers to write code in a more expressive and readable way, while Nock is responsible for executing the code at a lower and simpler level.

Hoon could be compared to C++ in the sense that it is a high-level language, and just as C++ is widely used to develop software for Windows and other platforms, Hoon is more expressive and readable, making it easier to write and maintain code. Nock, on the other hand, could be compared to Assembly in the sense that it is a low-level language and represents a level of abstraction closer to the hardware or the underlying virtual machine. Just as Assembly is a more direct representation of the instructions executed by the processor, Nock represents the fundamental operations executed by the Nock virtual machine in Urbit.

However, it is important to note that Nock is even simpler and more minimalist than Assembly language and is not directly related to hardware, as is the case with Assembly languages. Nock is a purely functional language, while Assembly is an imperative language based on processor-specific instructions.

Another comparison could be that Hoon is to Python as Nock is to Python bytecode. Python is a high-level, easy-to-read, and write language, just like Hoon. Python bytecode is the low-level representation of Python code, which is executed by the Python virtual machine (CPython), just as Nock is the low-level representation of Hoon code executed by the Nock virtual machine.

In summary, the architecture of Urbit at its most basic level works according to the image below:

Notice that any additional Urbit functionality will interact with the Arvo operating system, going through Hoon, until it reaches the Nock core.

Keep learning:

You can keep this study by reading this article about the Hoon language.