-
Notifications
You must be signed in to change notification settings - Fork 0
Language Guide
Hugo edited this page Jan 8, 2026
·
1 revision
The Nocta Language (.noc) is a C-like scripting language designed specifically for deep learning. It treats tensors as first-class citizens and provides high-level abstractions over the C library.
Variables are dynamically typed but can store strictly typed tensors.
var x = 10; // Integer
var y = 3.14; // Float
var s = "hello"; // String
var t = randn(5, 5); // TensorFunctions are defined with the var keyword for dynamic return types, or explicit types like void.
// Function definition
var add(int a, int b) {
return a + b;
}
// Void function
void log(string msg) {
print("[LOG] " + msg);
}Tensors support basic arithmetic operators which are broadcasted.
var a = ones(2, 2);
var b = ones(2, 2) * 2;
var c = a + b; // Element-wise additionStandard C-style control structures.
// If-else
if (loss < 0.01) {
print("Converged");
} else {
print("Continuing");
}
// While loop
var i = 0;
while (i < epochs) {
train_one_epoch();
i = i + 1;
}
// For loop (range)
// Syntax: for (var item in iterable)
for (var i in range(0, 10)) {
print(i);
}Classes allow you to bundle state and behavior, essential for defining Neural Network modules.
class Linear {
// Constructor method
void init(int in, int out) {
this.weight = randn(in, out) * 0.01;
this.bias = zeros(out);
// Enable gradients
requires_grad(this.weight, true);
requires_grad(this.bias, true);
}
var forward(var x) {
return matmul(x, this.weight) + this.bias;
}
}
// Usage
var layer = Linear();
layer.init(784, 128);
var out = layer.forward(input);// Single line comment