Nectar Primer

Ne Project Programming Language Documentation

Author: Amlal El Mahrouss (amlal at nekernel dot org)

Abstract

Low-Level large systems are one of the toughest aspects of Software Engineering.

Nectar was designed to implement such systems in a way that the programmer has the guarantee to know and design the system up to their wishes.

Nectar is simple to use, compiled to binary — and works on NeKernel and POSIX platforms.

Requirements

You will need to install:

  • NeBuild
  • CoreUtils
  • Git
  • MinGW/Clang

Hello Nectar!

Consider the following program:

let main()
{
    writefn("%s:13", "Hello, world!\n");
    return;
}

The following prints out 'Hello World' with a maximum buffer size of 13.

Now, consider this:

let main()
{
    let bar := "Hello, world\n";
    writefn("%s:13", bar);
    return;
}

You now know how to write a variable in Nectar.

We should make it constant though:

let main()
{
    const bar := "Hello, world\n";
    writefn("%s:13", bar);
    return;
}

Way better!

Hello Traits!

In this section we will be talking about the trait and impl keywords in Nectar.

Traits are rules used to describe implementations in Nectar, they work by giving specifications about how an impl should be mapped out.

Take it as a blueprint for let's say, an order-book.

trait order_book
{
   let buy(let self, let qty);
   let sell(let self, let qty);
};

An implementation would take care of implementing such methods for let's say, European order book, etc.

Hello Impls!

impl order_book : trait order_book
{
    let buy(let self, let qty) {  }
    let sell(let self, let qty) {  }
}

This implements the order book object from its traits order_book. More examples can be found on the repository of Nectar, or in the next page.