loading...
Cover image for How Nucleoid Learns
Nucleoid

How Nucleoid Learns

canmingir profile image Can Mingir ・3 min read

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

Alt Text

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.

We can expand the example with adding if statement like:

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

Alt Text

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"

Alt Text

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

Alt Text

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.

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

Alt Text

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

Posted on by:

Discussion

markdown guide