Skip to content

Language Basics

Single-line comments start with //.

comments.nyx
// This is a comment
auto x = 10; // Comment after code

Declare variables with auto. Types are inferred dynamically. Statements usually end with ;.

variables.nyx
auto message = "Hello Nyx";
auto count = 100;
auto active = true;
  • Numbers: Double-precision floating-point values.
numbers.nyx
auto pi = 3.14;
auto quantity = 10;
  • Strings: Sequences of characters in double quotes (").
    • Escapes: \" (double quote), \\ (backslash).
    • Literal sequences like \n, \r, \e in Nyx strings are processed into actual control characters by output functions (output, put) and relevant standard library functions when the string is used by them.
    • Interpolation: #{expression} embeds an expression’s string value.
strings.nyx
auto version = "1.0";
output("Nyx v#{version}\nRunning...");
  • Booleans: true or false.
booleans.nyx
auto isReady = true;
  • Lists: Ordered, mixed-type collections in []. Zero-indexed. Negative indices supported.
lists.nyx
auto items = [1, "apple", true];
output(items[0]); // 1
output(items[-1]); // true
auto combined = items + [2.5, "banana"];
auto repeated = ["go"] * 2; // ["go", "go"]
  • nyx_null: Represents a null or absent value.
nyx_null.nyx
auto data = nyx_null;
if (data == nyx_null) { output("Data is null."); }
  • SCRIPT_ARGS: A list of command-line arguments passed to the script. (See Getting Started).
  • Arithmetic: +, -, *, /, %
  • Comparison: ==, !=, <, <=, >, >=
  • Logical: and, or, not (keyword), ! (unary)
  • Assignment: =
  • Postfix Increment/Decrement: ++, -- (value = counter++;)
  • Member Access: . (for module members)
  • if/else: Conditional execution. Parentheses around condition are mandatory.
ifelse.nyx
if (x > 10) { output("Greater"); } else { output("Not greater"); }
  • for: C-style loop. Parentheses around clauses are mandatory.
forloop.nyx
for (auto i = 0; i < 3; i++) { output(i); }
  • break; / continue;: Exit or skip to next iteration of the innermost for loop.

Define with func. No semicolon needed after }. Implicitly return nyx_null if no return statement is executed.

functions.nyx
func multiply(a, b) = {
return a * b;
}
auto product = multiply(6, 7); // product is 42
  • output(expression);: Prints the string value of expression, then a newline. Processes \\n, \\e, etc., in string expressions.
  • put(expression);: Like output, but no trailing newline. Flushes output. Processes \\n, \\e, etc.
  • len(collection);: Returns length of a string or list.
  • @Typedef(expression);: A statement that prints the type name of the expression’s result (e.g., “NUMBER”, “STRING”).