var
- Used for declaring variables.const
- Declares a constant variable.function
- Declares a function.thematic
- Declares a thematic block (needs clarification in usage).statement
- Declares a standalone statement block.
class
- Declares a class.new
- Instantiates an object from a class.this
- References the current instance.super
- Calls a method from a parent class.extends
- Enables inheritance between classes.static
- Declares a static member of a class.
try
- Attempts code that may throw an error.catch
- Handles errors from atry
block.finally
- Executes cleanup code aftertry
orcatch
.throw
- Throws an error.
if
/else
- Conditional branching.for
- Loop over ranges or collections.while
/do
- Loop with condition checking.never
- Ensures a code path should never execute.switch
/case
/default
- Multi-branch selection.break
/continue
- Loop control statements.return
- Returns a value from a function.when
- Provides conditional execution.
import
- Imports modules or components.export
- Exports modules or components.from
- Specifies the source for imports.
del
- Deletes variables or object properties.unpack
- Extracts data from arrays or objects.watch
- Observes changes to variables or properties.defer
- Schedules tasks to run after scope exit.
typeof
- Returns the type of a value.copyof
- Creates a copy of a value.not
- Logical negation.memoize
/dememoize
- Manage cached function results.identity
- Returns its operand unchanged.void
- Evaluate an expression and returnundefined
.
in
/not in
- Membership test.as
- Casts a value to another type.of
- Checks ownership or belonging.and
/or
/nand
/nor
/xor
- Logical operators.instanceOf
/not instanceOf
- Tests type relationships.is
/is not
- Equality and inequality checks.
else if
- Alternative toif
/else
.not in
- Logical negation ofin
.is not
- Inequality check.not instanceOf
- Logical negation ofinstanceOf
.
- Must start with a letter, underscore, or dollar sign.
- Can contain letters, digits, underscores, and dollar signs.
- Cannot include spaces or special characters.
- Reserved keywords cannot be used as identifiers.
hypermatrix
hypermatrix1
_hypermatrix
$hypermatrix
Reserved for internal use or object member expressions:
true
,false
,null
,undefined
NaN
,Infinity
,_Infinity
this
,super
These identifiers are not currently reserved but using them may lead to issues
Enable precise function or member references by signature:
// Assigning a specific function
var SUM = #["sum(int, int)"];
// Using the identifier
println(SUM(1, 2)); // Output: 3
println(sum(1, 2) === SUM(1, 2)); // true
// Function definition
function sum(int a, int b) {
return a + b;
}
-
Single-line:
// This is a comment.
-
Multi-line:
/* Multi-line comments span multiple lines. */
-
Documentation:
/** * This documents a function or class. */
-
Section: Enhances organization in code blocks. Section comments are used to group related code sections for better organization. They must be visually distinct in IDEs to enhance readability.
Format rules:
- Start with at least three tildes: ~~~
- Can optionally start with pipe: |~~~
- Must end with at least three tildes: ~~~
- Can optionally end with pipe: ~~~|
Examples:
~~~ Section Name ~~~
|~~~ Section Name ~~~
~~~ Section Name ~~~|
|~~~ Section Name ~~~|
You can write code after a pipe-ended section:
~~~~~~~ Print ~~~~~~~| println("Hello, World!"); // This will print "Hello, World!"
~~~ Declaration ~~~ var a, b, c; ~~~~~~~~ Assignment ~~~~~~~~ a = 1; b = 2; c = a + b; ~~~~~~~~~ Print ~~~~~~~~| println(c); |~~~ End ~~~|
Lexer tags allow defining shortcuts or replacements for identifiers at the lexical analysis stage. These tags work before parsing, replacing tokens with predefined values.
#tag [identifier] :: [replacement tokens] ;;
- Tags replace occurrences of
[identifier]
with[replacement tokens]
. - The replacement happens before parsing, ensuring performance efficiency.
- Multi-line tags are supported until the
;;
delimiter is encountered.
#tag PRINT HELLO :: println("Hello"); ;;
#tag Name :: "Lexer Tags";;
#tag is yes :: == true;;
#tag is no :: == false;;
PRINT HELLO // Expands to: println("Hello");
PRINT HELLO // Still expands to println("Hello");
println(Name); // Expands to: println("Lexer Tags");
println(true is yes); // Expands to: println(true == true);
println(false is no); // Expands to: println(false == false);
Important Notes:
- Priority: Lexer tags take precedence over regular identifiers and keywords. If a tag shares a name with a keyword, the tag will be used instead.
- Overwriting: Defining a tag with an existing name will overwrite the previous definition.
- Scope: Tags work at the lexical analysis stage and do not affect runtime behavior.
- String:
'string'
,"string"
,`string`
,\\string\\
- Numeric:
123
,123.45
- Integer:
123
- Float:
123.45
- Hex:
0x7B
- Octal:
0o173
- Binary:
0b01111011
- Exponents:
1e+10
- Boolean:
true
,false
- Array:
[1, 2, 3]
- Tuple:
(1, 2, 3)
- Set:
<1, 2, 3>
- Matrix:
M[1, 2] | [3, 4]
- Object:
{key: value}
In HyperMatrix, string literals are versatile and designed to support a wide range of use cases, from simple text representation to dynamic, multi-line, and formatted strings.
Basic strings are enclosed in single ('
) or double ("
) quotes.
"Hello, World!"
'Hello, World!'
Multi-line strings are enclosed in backticks (`
) and support line breaks.
`This is a
multi-line string.`
\\...\\
→ Raw string mode (no escape processing)- Example:
\\-?\d+(\.\d+)?\\
→-?\d+(\.\d+)?
- Supports multi-line input, skipping leading/trailing newlines
- Example:
Raw strings are strings without any escape sequences, and support line breaks.
\\This is raw \ text \t no escapes \n \\
- Trim Leading Spaces:
- Lines are trimmed based on the lowest indentation level across all lines.
- Remove New Lines:
- The first and last lines' newlines are removed if they consist only of a newline character.
Example:
` Line 1
Line 2
Line 3`
Results in:
Line 1
Line 2
Line 3
- Using
"
or'
for multi-line strings causes an error. - Solution: Always use backticks (`) for multi-line strings.
- Placeholders must be valid expressions.
F"Invalid: #{undefinedVariable}"
This will throw an error if undefinedVariable
is not defined.
- Use double quotes (
"
) for strings that include single quotes. - Use single quotes (
'
) for strings that include double quotes. - Prefer formatted strings (
F""
) for dynamic content. - Always validate placeholders in formatted strings to avoid runtime errors.
String literals in HyperMatrix provide powerful ways to work with text, ensuring flexibility and ease of use for both simple and complex scenarios.
Formatted strings are postfixed with F
and allow embedding expressions within placeholders (#{}
).
F"Hello, #{name}!"
F"#{2 + 2} is equal to 4."
- Dynamic Expressions: Embed expressions that are evaluated at runtime.
- Nesting: Support for nested formatted strings.
Example:
F"Result: #{F"#{2 * 3} + #{4}"}"
Output:
Result: 6 + 4
\def[key]{value}
→ Defines a custom escape sequence.- Example:
\def[smile]{:))}
- Usage:
\smile
→:))
- Example:
- Supports dynamic replacements with indexed placeholders (
@index
):- Example:
\def[equal]{@0 == @1}
- Usage:
println(\equal{1}{0}); // 1 == 0 println(\equal{yes}{no}); // yes == no
- Example:
- Supports optional argument placeholders (
{}
):- Example:
\def[greet]{Hello, @0!}
- Usage:
println(\greet{John}); // Hello, John! println(\greet{Alice}); // Hello, Alice!
- Example:
\0
→ Null character\a
→ Bell/alert\e
→ Escape character\n
→ Newline\t
→ Tab\v
→ Vertical tab\r
→ Carriage return\b
→ Backspace (or binary escape when followed by digits)\f
→ Form feed\'
→ Single quote\"
→ Double quote\\
→ Backslash\{
→ Left curly brace ({
)\}
→ Right curly brace (}
)\[
→ Left square bracket ([
)\]
→ Right square bracket (]
)\s
→ Non-breaking space (\u00A0
)\z
→ Zero Width Non-Joiner (\u200C
)
\uXXXX
→ Unicode character- Example:
\u2764
→ ❤
- Example:
\xXX
/\x{XXXX}
→ Hexadecimal character- Example:
\x41
→ A
- Example:
\?;
→ Random ASCII character\?{abcde};
→ Random character from "abcde"\???
→ 3 random characters\?{01}??
→ Random binary with length 3\?8
→ Generate 8 random characters\?8{01}
→ Generate 8 random binary characters
\#Nchar;
→ Repeat character N times- Example:
\#5*;
→ *****
- Example:
\#N{text};
→ Repeat string N times- Example:
\#3{hi};
→ hihihi
- Example:
\|color|text
→ Changes text color- Example:
\|blue|Hello!
- Example:
\|#RRGGBB|text
→ Custom RGB text color\|###RRGGBB|text
→ Custom background color\|<|
→ Return to previous color (pop)\|<<|
→ Reset all colors (clear stack)\C[...]
→ Displays text in rainbow colors\C2{...}{...}[...]
→ Alternating colors every 2 characters
\cX
→ Control character escape- Example:
\cC
→Ctrl+C
- Example:
\M{name}
→ Named Unicode character- Example:
\M{heart}
→ ❤ - If not found, returns
\uFFFF
- Example:
- Expanded Unicode Support (Examples):
≈
,≠
,≥
,≤
,∞
,√
,©
,®
,™
,♥
,♫
,✔
,❌
α
,β
,γ
,π
,θ
,σ
,ω
,←
,↑
,→
,↓
,⇐
,⇒
♔
,♕
,♖
,♗
,♘
,♙
,😀
,😂
,🚀
,🔥
,⚠
\I;
→ Auto-incrementing number- Example:
"\I \I\I; \I"
→"0 1 3"
- A
;
after counting is ignored
- Example:
\b{binary}
→ Binary character (if followed by binary digits, otherwise backspace)- Example:
\b{01000001}
→A
- Example:
\0
/\124
→ Octal character- Example:
\47;21
→ Reads until hitting;
or a non-octal digit
- Example:
\x{41}
→ Hex character- Example:
\x41
→A
- Example:
\D[format]
→ Date- Example:
\D[yyyy-MM-dd]
→2025-02-04
- Example:
\T[format]
→ Time- Example:
\T[HH:mm:ss]
→14:30:15
- Example:
Escape sequences can also be used outside of strings, treating them as direct literals. This allows for more concise and readable code.
println(\n); // Prints a newline
println(\t); // Prints a tab space
println(\u2764); // Prints a Unicode heart (❤)
- Any escape sequence can be used without wrapping it in a string.
- This helps in cases where escape characters are frequently used without requiring explicit quotation.
- Useful for formatting, control characters, and inline symbols.
If an invalid escape sequence is used, an error message is thrown.
In HyperMatrix, the number literal formats supported, including integer, floating-point, and various base representations.
Hyper Matrix supports both integer and floating-point numbers:
- Integer Numbers: Whole numbers without a fractional part.
- Example:
42
,-7
,100000
- Example:
- Floating-Point Numbers: Numbers with decimal points.
- Example:
3.14
,-0.001
,100.0
- Example:
- Numbers with Exponents: Scientific notation representation.
- Example:
45e+2
(Equivalent to4500
)
- Example:
Binary numbers are prefixed with 0b
and contain only 0
and 1
.
- Example:
0b100110
(Equivalent to38
in decimal)
Hexadecimal numbers are prefixed with 0x
and use digits 0-9
and letters a-f
or A-F
.
- Example:
0xFE14D5
(Equivalent to16611605
in decimal)
Octal numbers are prefixed with 0o
and use digits 0-7
.
- Example:
0o521237
(Equivalent to172319
in decimal)
Hyper Matrix provides built-in parsing for both integer and floating-point values, ensuring accurate number representation and computations.
- Integer Parsing: Converts valid integer literals to numerical values.
- Floating-Point Parsing: Supports decimal and exponent notation.
const person = {name: "John", age: 30, weight: 70, height: 175, gender: "male"};
const {name, age} = person;
// name = "John"
// age = 30
const {PName: name, PAge: age} = person;
// PName = "John"
// PAge = 30
const {weight = 72, height = 180, bmi = 25} = person;
// weight = 70
// height = 175
// bmi = 25
const arr = [1, 2, 3, 4, 5];
const [a, b, c] = arr;
// a = 1
// b = 2
// c = 3
del a, b, c;
const [a, b, c, d = 41, e = 51] = [11, 22, 33, 44];
// a = 11
// b = 22
// c = 33
// d = 44
// e = 51
del a, b, c, d, e;
const [a, b] = (1, 2);
// a = 1
// b = 2
const (a, b, c) = true;
// a = true
// b = true
// c = true
del a, b, c;
const (a, b, c) = (1, 2, 3);
// a = (1, 2, 3)
// b = (1, 2, 3)
// c = (1, 2, 3)
del a, b, c;
const (a, b) = [1, 2, 3];
// a = [1, 2, 3]
// b = [1, 2, 3]
del a, b;
const a = (1, 2, 3);
// a = (1, 2, 3)
Used only in function, statement, and other parameters.
function sum(a, b) {
return a + b;
}
function sum(a: int, b: int) {
return a + b;
}
function sum(a: int = 1, b: int = 2) {
return a + b;
}
function sum(int a, int b) {
return a + b;
}
function sum(int a = 1, int b = 2) {
return a + b;
}
Units provide shorthand for multiplying numbers by predefined constants (e.g., 1m = m * 1
).
const float km = 1000;
const float m = 1;
const float cm = 0.01;
const string unit = "cm";
println(100cm == 1m); // true
println(1000m == 1km); // true
println(1000m == 1.1km); // false
println(1100m == 1.1km); // true
println(1.5km); // 1500
println(2cm); // 0.02
println(5unit); // "cmcmcmcmcm"
Error handling in HyperMatrix is still in development, currently supporting basic Syntax Errors and Runtime Errors. Future updates will introduce more robust exception handling, error propagation, and custom error definitions.
- Syntax Errors: Raised when code contains invalid syntax.
- Example:
Unexpected token '}' at line 3
- Example:
- Runtime Errors: Occur when executing invalid operations, such as type mismatches or undefined variables.
- Example:
Undefined variable 'x' used at line 5
- Example:
- Type Errors:
- Occur when attempting invalid type conversions or assignments.
- Example:
Cannot assign 'string' to 'number' variable
- IO Errors:
- Raised when file operations fail.
- Example:
File 'config.hm' not found in directory
- Index Errors:
- Triggered when accessing out-of-range indices.
- Example:
Index 10 is out of range for list of size 5
- Argument Errors:
- Occur when function arguments do not match expected values.
- Example:
Function 'sum' expects 2 arguments, but 3 were provided
- Module Errors:
- Raised when imported modules are missing or invalid.
- Example:
Module 'math' not found
- Custom Exception Types: Allowing developers to define and handle custom errors.
- Error Propagation: Improved stack tracing and debugging support.
- Structured Error Objects: Providing more detailed error messages and recovery options.
- Logging System: Implementing structured logs for debugging purposes.
- Enhanced Debugging Mode: Enabling verbose error reporting with detailed execution traces.
Stay tuned for upcoming improvements to make error handling more robust and developer-friendly!
Watchers allow observing and reacting to changes in variables, arrays, or object properties. This feature is experimental and will improve over time.
watch arr.pop() {
println("remove -> " + this);
}
watch arr.push() {
println("push -> " + this);
}
watch arr {
println("changed to -> " + this);
}
var arr = [1, 2, 3, 4, 5];
arr.push(6); // Prints: "push -> 6"
arr.pop(); // Prints: "remove -> 6"
arr = [1, 2, 3, 4, 5]; // Prints: "changed to -> [1, 2, 3, 4, 5]"
Defers allow you to schedule code execution for later, even after the current function has returned. They are useful for cleanup tasks or resource management.
Note: Defers execute at the end of their scope and have access to all variables within that scope.
defer {
println("defer");
};
defer (1000) {
println("program defer");
};
println("Program");
if (true) {
defer (2000) {
println("block defer");
};
println("Block");
}
println(sum(5, 6));
function sum(a, b) {
defer (1000) {
println("the sum = " + sum);
};
number sum = a + b;
return sum;
}
// Result:
// Program
// Block
// block defer
// the sum = 11
// 11
// defer
// program defer
Unpack extracts values from arrays or objects into variables for easier and more concise code.
// Example using a built-in object
unpack (system) {
println(screenWidth);
println(screenHeight);
keyPrint("windows", "tab");
}
var arr = [1, 2, 3, 4, 5];
unpack(arr) {
println(_0_); // 1
println(_2_); // 3
println(_4_); // 5
}
Prints a string with format like to the console without adding a newline.
printf(string, ...values);
Prints any value to the console without adding a newline.
print(...values);
Prints any value to the console and adds a newline.
println(...values);
Gets user input from the terminal.
input(before, after);
Evaluates a string as HyperMatrix code.
eval(code);
The System
object provides access to various system-level operations and properties.
System.setTimeout(callback, delay)
: Executes a function after a specified delay.System.setInterval(callback, delay)
: Repeatedly calls a function with a fixed time delay.System.setDoInterval(callback, delay)
: LikesetInterval
, but executes the callback immediately before starting.System.nextFrame(callback)
: Executes a function on the next animation frame.System.sleep(milliseconds)
: Pauses execution for the specified duration.
System.startTimer()
: Starts recording elapsed time.System.stopTimer()
: Stops the timer and returns the elapsed time.System.now()
: Returns the current timestamp.
System.setClipBoard(text)
: Sets the clipboard text.System.getClipBoard()
: Retrieves the current clipboard text.
System.beep()
: Plays a system beep sound.System.wait()
: Waits for user input.System.exit()
: Terminates the program.
System.monitorWidth
: Width of the primary monitor.System.monitorHeight
: Height of the primary monitor.System.monitorRate
: Refresh rate of the monitor.System.screenWidth
: Width of the screen.System.screenHeight
: Height of the screen.System.screenResolution
: Resolution of the screen.
System.getDesktopProperty(propertyName)
: Retrieves a desktop property value.System.pixelColor(x, y)
: Gets the color of the pixel at specified coordinates.
System.mouseLocation()
: Returns the current mouse position.System.mouseMove(x, y)
: Moves the mouse cursor to specified coordinates.System.mouseClick()
: Simulates a mouse click.System.mouseClickAt(x, y)
: Clicks at specified coordinates.System.mouseDoubleClickAt(x, y)
: Double-clicks at specified coordinates.System.mouseWheel(amount)
: Simulates mouse wheel scrolling.System.mousePress(...buttons)
: Simulates pressing mouse buttons.System.mouseRelease(...buttons)
: Simulates releasing mouse buttons.
System.keyPress(...keys)
: Simulates pressing keys.System.keyRelease(...keys)
: Simulates releasing keys.System.keyType(...keys)
: Simulates typing keys.System.keyPrint(...keys)
: Simulates pressing multiple keys simultaneously, then releases them all.
More functions will be added soon to expand system capabilities.
The Terminal
object provides functionality for interacting with the command line interface.
Terminal.printf(string, ...any)
: Prints text with format without adding a newline.Terminal.print(...any)
: Prints text without adding a newline.Terminal.println(...any)
: Prints text with a newline.
Terminal.input(before, after)
: Prompts the user for input.Terminal.readHidden(before, after)
: Prompts for hidden input (e.g., passwords).
Terminal.clear()
: Clears the terminal screen.Terminal.pause(repeatPause)
: Pauses terminal execution until user interaction.Terminal.ignore(numberOfChars)
: Ignores a specific number of input characters.
Terminal.args
: Retrieves command-line arguments passed to the program.
The terminal will support additional features:
- Text colors (foreground/background).
- Font styles (bold, italic, underline).
- Text markers and anchors for advanced text manipulation.
- Real-time text modifications and deletions.
- Math.HPI:
1.570796326794897
- Math.PI:
3.141592653589794
- Math.TAU:
6.283185307179588
- Math.E:
2.718281828459045
Math.abs(x)
: Returns the absolute value of a number.Math.acos(x)
: Returns the arccosine of a number.Math.asin(x)
: Returns the arcsine of a number.Math.atan(x)
: Returns the arctangent of a number.Math.atan2(y, x)
: Returns the arctangent of the quotient of its arguments.Math.ceil(x)
: Returns the smallest integer greater than or equal to a number.Math.clamp(value, min, max)
: Returns a value clamped betweenmin
andmax
.Math.cos(x)
: Returns the cosine of a number.Math.cosh(x)
: Returns the hyperbolic cosine of a number.Math.exp(x)
: Returnse
raised to the power of a number.Math.floor(x)
: Returns the largest integer less than or equal to a number.Math.hypot(x, y)
: Returns the square root of the sum of squares of its arguments.Math.int(x)
: Returns the integer value of a number.Math.log(x)
: Returns the natural logarithm of a number.Math.log10(x)
: Returns the base 10 logarithm of a number.Math.max(...values)
: Returns the largest of zero or more numbers.Math.min(...values)
: Returns the smallest of zero or more numbers.Math.onOff()
: Returns a random1
or0
.Math.pow(x, y)
: Returnsx
raised to the power ofy
.Math.random()
: Returns a pseudo-random number between0
and1
.Math.round(x)
: Rounds a number to the nearest integer.Math.sign(x)
: Returns the sign ofx
, indicating whetherx
is positive, negative, or zero.Math.sin(x)
: Returns the sine of a number.Math.sinh(x)
: Returns the hyperbolic sine of a number.Math.sqrt(x)
: Returns the positive square root of a number.Math.tan(x)
: Returns the tangent of a number.Math.tanh(x)
: Returns the hyperbolic tangent of a number.Math.toDegrees(x)
: Converts radians to degrees.Math.toPoint(x, y)
: Creates a point fromx, y
coordinates.Math.toRadians(x)
: Converts degrees to radians.
- Advanced 2D/3D mathematical operations.
- Geometric transformations.
- Statistical calculations and complex number support.
- Specialized classes for 2D/3D math (e.g.,
Math2D
,Matrix2D
,Vector2D
).
- Status: Coming Soon
- Status: Coming Soon
- Ideas Needed: Potential future addition for time-based intervals.
- Status: Work in Progress
- Status: Coming Soon
- Status: Coming Soon
- Status: Coming Soon
- Status: Coming Soon
- Status: Coming Soon
- Not sure if this is needed, but it could be a nice addition for advanced use cases.
Represents any type of value.
<any> = undefined
<any> = null
<any> = 1
<any> = "string"
<any> = [1, 2, 3]
<any> = <%AnyOtherType%>
Automatically detects and assigns the type based on the value.
<any> >>> <auto> = 1 // auto becomes int
<any> >>> <auto> = 1.0 // auto becomes float
Special types for absence of value.
<any> >>> <null> = null
<any> >>> <undefined> = undefined
Represents both integers and floating-point numbers.
<any> >>> <number> >>> <float> = 1.0
<any> >>> <number> >>> <float> >>> <int> = 1
<any> >>> <number> >>> <float> >>> <NaN> = NaN
<any> >>> <number> >>> <float> >>> <Infinity> = Infinity
Represents sequences of characters.
<any> >>> <string> = "hello"
<any> >>> <string> = ""
Represents true or false values.
<any> >>> <boolean> = true
<any> >>> <boolean> = false
<any> >>> <array> = [1, 2, 3]
<any> >>> <array> = ["hello", "world"]
<any> >>> <tuple> = (1, 2)
<any> >>> <tuple> = (1, 2, [3, 4])
<any> >>> <set> = <1, 2, 3>
<any> >>> <set> = <1, "a">
<any> >>> <matrix> = M[1, 2, 3]
|[4, 5, 6]
|[7, 8, 9]
Represents key-value pairs.
<any> >>> <object> = {a: 1, b: 2}
<any> >>> <object> = {key: "value"}
function sum(a, b) {
return a + b;
}
<any> >>> <Function> >>> <AnonymousFunction> = (a, b) -> a + b
Defines logical groupings with specific behavior.
thematic fullname {
return "Hyper" + "Matrix";
}
Defines blocks with structured logic.
statement loop: block {
~> (int times = 10) {
for (int i = 0; i < times; i++) {
block({index: i});
}
}
}
Directly tied to the language’s core.
NativeFunction
NativeStatement
NativeThematic
// Regular Block
{
println("Hello World");
}
// Single-Line Block
println("Hello World");
// Empty Block
{}
5 + 5 = 10
5 - 5 = 0
5 * 5 = 25
5 / 5 = 1
7 % 5 = 2
5 ** 5 = 3125
5 + 5 * 5 = 30 -> 5 + (5 * 5)
(5 + 5) * 5 = 50
+4 = 4 // Positive
-4 = -4 // Negative
++4 = 5 // Increment
--4 = 3 // Decrement
%%4 = 16 // Squaring
4++ = 4 // Post-increment, value updates to 5 after use
4-- = 4 // Post-decrement, value updates to 3 after use
4%% = 4 // Post-squaring, value updates to 16 after use
5 > 4 = true
5 < 4 = false
4 >= 4 = true
5 <= 4 = false
5 == 5 = true
5 != 5 = false
5 === 5 = true
5 !== 5 = false
5 === "5" = false
5 !== "5" = true
5.1 ~= 5 = true
5.1 !~= 5 = false
5.1 ~= "5" = true
5.1 !~= "5" = false
5.1 ~= 5.0 = true
5.1 !~= 5.0 = false
"Hyper" + "Matrix" = "HyperMatrix"
"Matrix" + " " + "Grammar" = "Matrix Grammar"
"HyperMatrix" - "r" = "HypeMatix"
"Hello, World" * "o" = "HellO, WOrld"
"Hello, World" / "o" = "Hell _, W _rld"
"hello" == "hello" = true
"5.236" == 5.236 = true
"hello" != "hello" = false
"5.236" != 5.236 = false
"HeLlo" ~= "hello" = true
"HeLlo" !~= "hello" = false
true + true = true
true + false = true
5 + true = 6
5 - false = 5
5 * true = 5
5 * false = 0
true == true = true
true !== "true" = true
true >= false = true
false <= true = true
null ?? "hello" = "hello"
undefined ?? "hello" = "hello"
true || false = true
false && true = false
1 || 2 = 1
0 || 3 = 3
!true = false
!false = true
typeof true = boolean
typeof "ok" = string
copyof 1 = 1 // Creates a new pointer
identity true = {"type": "boolean", "value": true}
void 1 = undefined
void "hello" = undefined
memoize 5 * 5 + 5 = 30 // Save for later
5 * 5 + 5 = 30 // Returns saved result
memoize factorial(5) = 120 // Save for later
dememoize 5 * 5 + 5 = 30 // Recalculates and deletes saved result
dememoize factorial(5) = 120 // Recalculates and deletes saved result
true
false
1
0
-1
-9223372036854775808 // min int64
9223372036854775807 // max int64
1.0
0.0
-1.0
-1.7976931348623157e+308 // min float64
1.7976931348623157e+308 // max float64
""
"Hello World"
"Hello\nWorld"
"Hello\tWorld"
"Hello\rWorld"
"\u0126"
F""
F"Hello #{\"World\" * 5}" = "Hello WorldWorldWorldWorldWorld"
F"#{"Hello" * 5} #{"World" * 5}" = "HelloHelloHelloHelloHello WorldWorldWorldWorldWorld"
F"#{F"#{F"#{F"#{F"#{"Hello World"}"}"}"}"}" = "Hello World"
[]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
["string", true, 1, 1.5, [1, 2, 3], {"key": "value"}]
(1, 2)
(1, 2, 3, 4, 5, 6, 7, 8, 9)
([1, 2, 3], [4, 5, 6], [7, 8, 9])
("string", true, 1, 1.5, [1, 2, 3], {"key": "value"}, (1, 2, 3))
<>
<1, 2, 3>
<[1, 2, 3], [4, 5, 6], [7, 8, 9]>
<"string", true, 1, 1.5, [1, 2, 3], {"key": "value"}, (1, 2, 3), <1, 2, 3>>
M[]
M[1, 2, 3]
|[4, 5, 6]
|[7, 8, 9]
M[1, 0.5, true]
|["Hello", false, [F"Name: #{name}", 2.5, false]]
|[(1, true, "OK"), <0.1, 0.2, 0.5>, M[1, 2] | [3, 4]]
M[1] M[1, null, null]
|[2, 3] |[2, 3, null]
|[4, 5, 6] same as |[4, 5, 6]
{}
{"key": "value"}
{"key": "value", key2: "value2"}
{key, "ey2": "value2", "key3": "value3"}
() -> {}
function() {}
a -> {}
(a, b) -> {}
(a, b) -> a + b
(a, b) -> { return a + b }
function(a, b) { return a + b }
function(a) a * a
thematic {
return "hello, world!";
} value {
println("Hello World" + value);
}
thematic: string {
return "hello, world!";
} value {
println("Hello World" + value);
}
thematic: string {
return "hello, world!";
} value: string {
println("Hello World" + value);
}
thematic: string {
return "hello, world!";
} string value {
println("Hello World" + value);
}
statement: block {
~> (n) {
if (n > 0) {
println("positive");
} else if (n < 0) {
this.isNegative();
} else {
this.isZero();
}
} isZero {
println("zero");
} isNegative {
println("negative");
}
}
statement: blk {
~> (n) {
if (n > 0)
blk({num: n});
else this.isZero(n);
} isZero(n) {
if (n == 0)
blk({num: n});
else this.isNegative(n);
} isNegative(n) {
if (n < 0)
blk({num: n});
}
}
statement: block {
~> (int chance = 50) {
block() when true.flip(chance) else this.Else();
} Else {
block();
}
}
statement: block {
~> (int times = 10, int index = 0, update = 1) {
for (int i = index; i < times; i += update) {
block({index: i});
}
}
}
<identifier>
ident = ""
ident52 = ""
ident_52 = ""
_ident_52_ = ""
$ident = ""
$ident$52$ = ""
$ident_52$ = ""
_$ident = ""
#[<string>]
Row identifiers allow referencing functions or members by their exact signature.
var newVar = #["sum(int, int)"];
(<identifier> | <member>) . <identifier>
(<identifier> | <member>) . <call>
(<identifier> | <member>) . <member>
(<identifier> | <member>) . <memberCall>
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.length = 9;
arr.push(10);
<identifier>()
<member>()
var func = () -> println("Hello World");
func();
system.wait(500);
<identifier> = <expression>
<member> = <expression>
<pattern> = <expression>
var arr;
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.length = 5;
<identifier> as <identifier>
<member> as <identifier>
<call> as <identifier>
true as string = "true";
5 as string = "5";
5.0 as string = "5.0";
5.62 as int = 5;
5 as float = 5.0;
Math.PI as int = 3;
sum(5.7, 5.3) as int = 11;
const float PI = 3.14159;
int INT_PI = PI as int; // INT_PI = 3
#<identifier> <identifier>
#<identifier> <member>
#<identifier> <call>
#boolean "" = false;
#boolean " " = true;
#int true = 1;
#int false = 0;
#int "1" = 1;
#int 1.0 = 1;
#int Math.OnOff() = 1 or 0;
sub(5, 5) as string = "0";
<condition> ? <expression> : <expression>
<condition> ? <truecase> : <falsecase>
<condition> ? <truecase>
1 < 2 ? 1 : 2 = 1;
Math.random() > 0.5 ? "Head" : "Tail" = "Head" or "Tail";
Math.round(5.5) == 6 ? "Up" : "Down" = "Down";
Math.random(0, 100) % 2 === 0 ? "Even" : "Odd" = "Even" or "Odd";
<expression> when <condition> else <expression>
<truecase> when <condition> else <falsecase>
<truecase> when <condition>
5 when 1 < 2 else 10 = 5;
"Head" when Math.random() > 0.5 else "Tail" = "Head" or "Tail";
"Up" when Math.round(5.5) == 6 else "Down" = "Down";
"Even" when Math.random(0, 100) % 2 === 0 else "Odd" = "Even" or "Odd";
new <identifier>(<expression>...)
new <class name>(<expression>...)
new <type name>(<expression>...) // ASAP :D
new Matrix(true, 50); // in progress...
new File("file.txt"); // not implemented
new Date(2023, 1, 1); // coming soon...
new <type name>(); // coming soon...
<expression> => <identifier>
load("file.txt") => file;
var data;
var dataStr;
Json.toObject(dataString) => data;
Json.toString(data) => dataStr;
// Json class coming soon...
(<identifier> | <member> | <call>) |> <member>
|> <memberCall>
|> <member>
|> <memberCall>
@return <expression> // the same start point of the chain
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
println(arr); // [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr
|> add(10).add(10.5)
|> add(11)
|> add(12)
|> add(13)
|> pop()
|> add(14)
|> add(15);
println(arr); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10.5, 11, 12, 14, 15]
(<identifier> | <member> | <call>) &> <AnonymousFunction>
&> <AnonymousFunction>
&> <AnonymousFunction>
&> <AnonymousFunction>
@return <expression> // result of the last anonymous function
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
println(arr); // [1, 2, 3, 4, 5, 6, 7, 8, 9]
var newArr = arr
&> nums -> nums.filter(b -> b % 2 === 0) // filter any non-even number
&> nums -> nums.map(b -> b * 2); // double all numbers
println(newArr); // [4, 8, 12, 16]
var square = arr -> arr.map(n -> n * n); // define the square line-persand anonymous function
const number sum = newArr
&> square
&> #["sumOfAll(array)"];
println(sum); // 480
function sumOfAll(array arr): number {
return arr.reduce((sum, n) -> sum + n);
}
var <identifier> = <expression>
const <identifier> = <expression>
var <identifier>: <type> = <expression>
const <identifier>: <type> = <expression>
var <pattern> = <expression>
const <pattern> = <expression>
var <pattern>: <type> = <expression>
const <pattern>: <type> = <expression>
<type> <identifier> = <expression>
const <type> <identifier> = <expression>
function <identifier>(<paramspattern>) <block>
function <identifier>(<paramspattern>): <type> <block>
<type> <identifier>(<paramspattern>) <block>
thematic <identifier> <getblock> <identifier> <setblock>
thematic <identifier>: <gettype> <getblock> <identifier> <setblock>
thematic <identifier>: <gettype> <getblock> <identifier>: <settype> <setblock>
thematic <gettype> <identifier> <getblock> <identifier>: <settype> <setblock>
thematic <gettype> <identifier> <getblock> <settype> <identifier> <setblock>
statement <identifier>: <identifier> <block> {
~>(<paramspattern>) <block>
<identifier>(<paramspattern>) <block>
<identifier> <block>
...
}
statement <identifier>: <identifier> <block> {
~> <block>
<identifier>(<paramspattern>) <block>
<identifier> <block>
...
}
class <identifier> {
<variabledeclaration>...
<functiondeclaration>...
<thematicdeclaration>...
<statementdeclaration>... // soon
}
class <identifier> extends <identifier> {
<variabledeclaration>...
<functiondeclaration>...
<thematicdeclaration>...
<statementdeclaration>... // soon
}
if (<condition>) <block>
if (<condition>) <block>
else <block>
if (<condition>) <block>
else if (<condition>) <block>
else <block>
if (<condition>) <block>
else if (<condition>) <block>
else if (<condition>) <block>
else if (<condition>) <block>
else <block>
if <<condition>> <block>
else if (<condition>) <block>
else if (<condition>) <block>
else if (<condition>) <block>
switch (<expression>) {
case <expression>: <inCaseBlock>
break
case <expression>: <inCaseBlock>
break
default: <inCaseBlock>
}
switch (<expression>): <comparison> {
case <expression>: <inCaseBlock>
break
default: <inCaseBlock>
}
for (<initstatement>; <condition>; <updateexprsion>) <block>
for (<variabledeclaration> of <expression>) <block>
for (<variabledeclaration> in <expression>) <block>
while (<condition>) <block>
while (<condition>) <block>
never <block>
do <block> while (<condition>)
try <block>
catch (<expression>) <block>
finally <block>
watch <expression> <block>
defer (<expression delayInMillis>) <block>
defer <block>
unpack (<expression>) <block>
break
break when <condition>
continue
continue when <condition>
return <expression>
return when <condition>: <expression>
return when <condition>
return when <condition>; // return undefined
throw <expression>
throw when <condition>: <expression>
throw when <condition>
throw when <condition>; // stop program and throw default error
del <identifier>
del <identifier>, <identifier>, ...
del <member>
del <identifier>, <member>, <member>, ...
del <tuplepattern>
import <string>
import <string> as <identifier>
import from <string>
import <objectpattern> from <string>
import * from <string>
import <objectpattern> as <identifier> from <string>
// module importing
import <identifier>
import <identifier> as <identifier>
import from <identifier>
import <objectpattern> from <identifier>
import * from <identifier>
import <objectpattern> as <identifier> from <identifier>
export <identifier>
export <declaration>
export <objectpattern>
{
<anystatement>...
}
Archetypes enable prototype-like behavior for both native and user-defined types in HyperMatrix. They provide a flexible way to extend and customize functionality for any data type, including string
, int
, float
, array
, and user-defined classes.
- Prototype Functionality: Archetypes act as prototypes, offering foundational behavior that can be extended or customized.
- Memory Efficiency: Unique archetypes (
uniquearche
) are created only when accessed, reducing memory usage. - Simplified Behavior Modeling: Archetypes make it easier to add or override functionality for both built-in and custom types.
- Global Archetype (
archetype
): Defined at runtime and shared across all instances of a type. - Unique Archetype (
uniquearche
): Defined on individual objects but only created when accessed.
var str = "ok";
// Initially, `str` does not have a unique archetype.
println(str.length); // Accesses the global archetype.
// Now, `str` has its own unique archetype.
println(str.__arche__);
Custom archetypes allow developers to extend or override behavior for built-in or user-defined types.
// Adding methods to string and number archetypes
string.archetype.print = () -> {
println(this);
};
number.archetype.half = () -> {
return this / 2;
};
"Hello".print(); // Output: Hello
println((12).half()); // Output: 6
Archetypes can also be applied to user-defined classes, making it easy to share functionality across multiple instances.
class Person {
var name;
var age;
}
Person.archetype.greet = () -> {
println("Hello, my name is " + this.name);
};
var john = new Person();
john.name = "John";
john.greet(); // Output: Hello, my name is John
Archetypes can be inspected in two ways:
-
Using the
identity
Unary Operator:println(identity "Matrix"); // Displays an object with the value's archetype information.
-
Accessing the
__arche__
Property:println("Matrix".__arche__); // Outputs the archetype object for the string.
string.archetype.reverse = () -> {
return this.split('').reverse().join('');
};
println("HyperMatrix".reverse()); // Output: xirtemrepyH
class Animal {
var species;
}
Animal.archetype.describe = () -> {
println("This is a " + this.species);
};
var dog = new Animal();
dog.species = "Dog";
dog.describe(); // Output: This is a Dog
Archetypes in HyperMatrix provide powerful tools to customize and extend type behavior while maintaining performance and memory efficiency. They are designed to simplify complex object modeling and make the language more expressive.
HyperMatrix combines two key concepts:
- "Hyper": Represents a high-level programming language designed for ease of use for both beginners and experts.
- "Matrix": Highlights its specialized support for matrix-like operations and data structures, complete with extensive built-in functions.
- A high-performance programming language optimized for matrix operations, applications, and games.
Note: While current performance metrics are not finalized, future versions aim to deliver significant performance improvements.
Lead Developer: @DreamProgrammer
- Start Date: 2024-10-04
- Completion Date: 2024-12-11
- Release Date: 2025-02-18
- Focused on improving stability, error handling, and shell enhancements.
- Fixed block parsing issues and improved identifier tracking in errors.
- Refined error handling with 40% better efficiency and more detailed messages.
- Added new command-line flags:
-version
to display language version details.-grammar
to retrieve the grammar file.- Modified
-help
to provide a basic usage guide.
- Improved interactive mode:
run
now repeats the last executed file if no arguments are provided.- Shows usage guidance if no file has been previously executed.
- Expanded escape sequences:
- Added
{}
,[]
,\s
, and\z
as new escapes. - Improved rainbow text rendering and structured color effects.
- Added
- Performance enhancements:
- Parsing speed increased by reducing unnecessary checks.
- Optimized binary, octal, and hex escapes for efficiency.
- Introduced over 100 Unicode character escapes, including symbols, arrows, chess pieces, emojis, and more.
- Release Date: 2025-02-05
- Major improvements to the lexer and parser:
- Rebuilt the lexer for increased efficiency and flexibility.
- Rebuilt the parser to enhance usability and future-proofing.
- Prepared the lexer and parser for upcoming syntax settings updates.
- Expanded numeric support:
- Added binary (
0b100110
), hexadecimal (0xfe14d5
), octal (0o521237
), and exponent (45e+2
) number lexing.
- Added binary (
- Introduced multi-word keywords:
- Now supports combinations like
is not
,is null
, andhash tag
as distinct keywords.
- Now supports combinations like
- Added static initializers for classes:
- Use
static { }
blocks to initialize static variables in order.
- Use
- Unit expressions are now stable:
- Support for numeric types with units (e.g.,
45m
,5.3cm
,0b100110turn
).
- Support for numeric types with units (e.g.,
- Performance improvements:
switch
andif
statements now execute 76% faster.- Fixed infinite loop caused by unclosed parentheses
(5
.
- AST Serialization Support:
- Introduced
.hpr
format for fast-loading pre-parsed code.
- Introduced
- Expanded Escape Sequences:
- Introduced advanced formatting, Unicode, and control characters.
- New capabilities include color formatting, text repetition, randomized characters, and date/time formatting.
- Internal Version: This version was skipped as it was dedicated to extensive lexer testing and validation. Improvements and optimizations from this phase have been incorporated into version 1.0.6 for public release.
- Release Date: 2025-01-25
- Introduced significant shell updates and new command-line flags:
- Removed colors from shell output and error messages for better compatibility with all terminals.
- Added a
-time
flag to display the execution time of the program. - Added a
-lib:<path>
flag for attaching library folders to the current run. - Added a
-setup
flag for setting up a HyperMatrix project in the current or specified folder. Automatically exits after setup is complete. - Added a
-settings:<path>
flag to attach settings for the current run (to be fully supported after lexer updates). - Added a
-resource:<path>
flag to attach resources for the current run. - Added a
-help
flag to display grammar documentation in Markdown format and exit the program. This flag takes precedence over others.
- Improved the shell start message for a better user experience.
- Fixed an issue where the
this
keyword could not be used inside thematic blocks.
- Release Date: 2025-01-20
- Addressed several critical issues:
- Fixed shared property conflicts in class instances.
- Corrected
this
object scoping and function display in the console. - Resolved issues with accessing instance variables in
-continue
mode. - Improved instance representation: displays
stringify
method if available. - Refactored archetypes for better memory optimization and performance.
- Enhanced compiler performance and improved multi-line comment handling.
- Introduced archetype enhancements, including user-defined archetypes and better value introspection via
identity
or__arche__
. - Added flexible import syntax with aliasing support.
- Introduced
printf(string, ...args)
for formatted output.
- Internal Version: This version was skipped as it focused on internal refactoring of archetypes and optimization work. Changes were included in version 1.0.3 for public release.
- Release Date: 2025-01-11
- Addressed several known issues:
- Resolved class declaration conflicts in
while
scopes. - Enhanced reverse assignment functionality for nested scopes.
- Improved support for
undefined
types with logical operators (is
andis not
). - Fixed multiple evaluation of assignments to ensure consistent behavior.
- Corrected behavior of logical operators (
and
andor
). - Updated
break
,continue
, andreturn
statements to properly stop only the intended scope or loop. - Refactored multi-line string processing for improved handling of backticks and better error reporting.
- Resolved class declaration conflicts in
- Added descriptive error messages for improper use of multi-line string delimiters.
- Release Date: 2025-01-05
- Initial public release.
- Bug fixes and stability improvements.
- Function naming improvements and standardization.
Thank you for exploring the HyperMatrix programming language! This is just the beginning of what I envision as a powerful and accessible tool for developers.
Continuous Improvement: All the features described here are part of the initial release and will be improved and expanded over time. Your feedback and suggestions are invaluable in shaping the future of this language. Join the Journey: If you’re passionate about programming languages and would like to contribute to HyperMatrix, I’d be thrilled to have you join the project. Whether it’s coding, testing, or documentation, your help is welcome! Feel free to reach out or contribute through the project’s repository. Together, we can make HyperMatrix something truly special.
- DreamProgrammer