How Nucleoid Learns

Can Mingir
Jul 23 · 4 min read
Image for post
Image for post

The short and long answer is Graph.

This article explains mechanics inside of the runtime, for basic usage:

Nucleoid is a declarative runtime, which means instead of compiling code files, it accepts ES6 codes (JavaScript) in-flight and builds graph. The purpose of doing this is making connection between statements, so that, the runtime can draw its own control flow and provide logical conclusion. Let’s start with a simple example:

> a = 1
> b = a + 2
> c = b + 3
Image for post
Image for post

Each statement of a = 1, b = a + 2 and c = b + 3 is received into system in separate times, since a is part of b‘s definition, the runtime draws dependency line between two, and when a is changed, the runtime automatically updates value of b, and rest of follows the same for c so on and so forth.

> a = 2
> b
4
> c
7

We can expand the example with adding if statement like:

> if ( c > 10 ) { d = true } else { d = false }
> a = 6
> d
true
Image for post
Image for post

In this case, Nucleoid runtime also considers if statement as a data and includes in the graph along with its true and false blocks, and changing a triggers chain event through all the way to variable d by the runtime. As a result, the runtime respects declarative statements and conclude logical integrity.

In this paradigm, there is no segregation regarding what data is or not, instead approaches how data is related with others so that any type of data including business rules can be added without requiring any additional actions such as compiling, configuring, restarting as a result of plasticity.

The same concept can be applied to class/object relationships as well:

> class Student {}
> student1 = new Student()
> student1.firstName = "First"
> student2.LastName = "Last"
Image for post
Image for post

In this case, a relationship between Student and student1 is class and instance as well as the graph carries properties of instance. In addition, the graph keeps all relationship among statements in order to provide logical integrity as receiving more statements. For example, if there is class-level declaration, it will be still part of the graph:

> Student.fullName = Student.firstName + " " + Student.lastName
Image for post
Image for post

Class-level declaration adds more edges in graph in order to fulfill logical integrity. So, student.fullName is derivated to student1.fullName since student1 is one instance of Student, so that, the runtime calculates fullName property using firstName and lastName properties.

Nucleoid as a Database

At the same time, as Nucleoid building graph and holding state in a memory, the runtime also stores statements, so that, it doesn’t require external database. In short, Nucleoid runs as programming runtime plus database.

As conclusion, Nucleoid follows steps as:

  1. Receive ES6 (JavaScript) code without compile or restart
  2. Builds Graph based on relationship of statements
  3. Runs statement in the state
  4. Provide logical integrity based on information in graph
  5. Stores statements so that it doesn’t require external database
  6. or roll back transaction if any error occurs
Image for post
Image for post

Nucleoid is an open source (Apache 2.0), a runtime environment that allows declarative programming written in ES6 (JavaScript) syntax. Since statements are declarative, the runtime provides logical integrity and persistency as hiding technical details.

Learn more at nucleoid.org/tutorial

Nucleoid

Declarative Runtime System

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store