Getting Started with the Neuron Language | Hacker Noon

Author profile picture

A step-by-step guide to developing with Neuron.
With

npm

installed, type the following into your command line:

npm install --global neuron-lang

Create a new file

Create a file with the name

main.neuron

. This will contain our program. In the command line, navigate to the directory with the file:

cd path/to/main.neuron

Create a simple Hello, World! program

In

main.neuron

, type the following:

sayHello {
 log(Hello #0!);
}
This is the standard function and object syntax, with

#0

being the first parameter passed as an argument to the function

sayHello

. The function can now be called as follows:

sayHello(world);

This will now log “Hello world!”

Inline functions

We can create a new function that can return a value as well. In main.neuron:

sayHello {
 return(Hello #0); // or return: Hello #0
}

log([sayHello => world] in Neuron!);
When run in the command line with

neuron main.neuron

, it should log “Hello world in Neuron!”

Passing multiple parameters

Now we can pipe the output of another function into our

sayHello

function:

add {
 return(#0 plus #1 is [#0 + #1].);
}

sayHello {
 log(Hello! It appears as though [add => #0 #1]!);
}

sayHello(0, 1);

The output of our program should be “Hello! It appears as though 0 plus 1 is 1.”

Iterators

We can further extend the capabilities of our program with iterators:

for (i => 10) {
 sayHello(#i, [#i  -  1]);
}
This will now log “Hello! It appears as though 0 plus -1 is 0.” and “Hello! It appears as though 1 plus 0 is 1.” until the iterator, represented by

#i

, has reached nine.

Other features of the Neuron programming language capable of being integrated in our program include conditionals, variables, iterators, and objects.

Running the program

With Neuron installed through

npm

, the file can be executed as such:

neuron main.neuron

What next?

Resources

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!

read original article here