mxLang Documentation

A programming language for Maximo administration. Built by technical consultants for technical consultants.

Running MxLang from the command line

From the command line, ensure you are in a directory that contains the executable and the file

The source file must contain the .mx extension.

Ensure to pass the file name as an argument to the executable.

./mxlang [filename]

Quick Example

Variables

var a = "hello";
print a;

>> hello

Loops

for( var a = 0; a < 10; a = a + 1) {
    print a;
}

>> 0, 1, 2, 3, 4 ....

Functions

fun print_this() {
    print true;
}

print_this();

>> true

Writing your unit tests

Unit tests in mxlang are simple.

The unit tests are created in the same source file from which you are working in.

MxLang will determine if a function is a unit test if and only if each function is decorated with a @test decorator above the function name.

Available Test Functions

fail( "fail message" );

The test will fail at the point from which this is called.

assertEquals(a, b);

Checks to see if a and b are equal. If this check fails, the test fails.

pass();

The test passes at the point from which this is invoked.

failNow();

The unit test fails and the program exits completely at this point.

Examples:

@test
fun the_testing_function_name {
    print "test";
}
@test
fun failing_test {
    if( a > 5 ) {
        fail("this has failed");
    }
    else {
        pass();
    }
}

When the program runs, the unit testing functions will automatically be called sequentially. You do not need to call the unit testing function name directly.

Implicit Functions

Here are some native functions you can call anytime in your code.

print( something ); -> null

Prints to the console.

typeof( something ); -> T

Returns the baseline class of the parameter.

length( "string" ); -> Double

Returns the length of a string.

int( number ); -> Integer

Casts the number to an integer value.

clock(); -> Object

Returns the current time in milliseconds (good for timing requests etc)

Core Library

MxLang contains a core library, natively built into the language.

To use these libraries, include a "use" statement at the top of the script.

use "library name"

Instances

These are effectively objects that are passed around in your code. Instances have methods that you can call to do something. They are not core to the library you can use as individual modules, however are used to contain data and compute on that data.

# utils

This library contains all of the native data structures needed to build deeper logic into your scripts.

use "utils"

array

.new(element, element, element, ...); -> ArrayInstance

Makes a new array with n elements included as params.

var a = array.new(1,2, 3, 4);
print a.listAll();

>> 1, 2, 3, 4
.append(element); -> null

Adds a new element to the array.

.getAt(n); -> element

Returns the value at the nth index. n is a number.

.setAt(n, p); -> null

Sets the value of p at index n.

.listAll(); -> null

Prints out all of the values in the list.

.size(); -> Integer

Returns the size of the list.

dictionary

.new( $(key, value), $(key, value) ); -> DictionaryInstance

Makes a new dictionary that contains key value pairs. (hashmap)

.put(element, element); -> null

Adds a new element to the dictionary.

.containsKey(element); -> boolean

Returns a boolean value if the key exists.

.getValueFromKey(n); -> element

Returns the element for the key.