Basic Constructs and Operations SocioCortex

Basic Constructs and Operations

Arithemtic Operations

MxL provides the common operators for the arithmetic addition (+), subtraction (-), multiplication (*), and division (/), as well as for the power operation (^).

Furthermore, MxL minds the usual precedence of these operators, i.e. multipliation and division will be evaluated before addition and subtraction. Round brackets may be used to apply an explicit order of evaluation.

The plus-operator is also be used for the concatenation of strings.

The following table lists some exemplary arithmetic and concatenation operations:

Exemplary Expression Result
1 + 2 * 3 7
(1 + 2) * 3 9
(1 - 2) / (3 + 4) -0.143
1 / 0 Error: Division through zero
"Hello " + "World" "Hello World"

Comparison and Logical Operators

In order to compare certain instances, MxL provides also a basic set of common comparison operators:

Symbol Name Description
= equal Tests if two instances of type object are equal
<> not equal Tests if two instances of type object are different
> greater than Tests if the left number/date is greater/is after the right number/date
>= greater than or equal Tests if the left number/date is greater/is after the right number/date, or if they are equal
< less than Tests if the left number/date is less/is before the right number/date
<= less than or equal Tests if the left number/date is less/is before the right number/date, or if they are equal

All these operators return either true or false. To combine multiple comparisons, MxL provides the logical inversion, conjunction, and disjunction, whereas inversion will be evaluated before the conjunction, which in turn will be evaluated before the disjunction:

Symbol Description
not Inverts the subsequent boolean value
and Applies the logical conjunction on two boolean values
or Applies the logical disjunction on two boolean values

The following table lists some exemplary comparison and logical operations:

Exemplary Expression Result
1 + 2 < 3 false
2 + 3 = 5 true
3 + 4 > 5 and true true
true and false or true and not false true

Basic Language Constructs

In addition to the previous mentioned operators, MxL supports the following set of language constructs:

Name Syntax Description Examplary Expression
comment /* <any comment> */ A textual comment which won’t be interpreted by the MxL Parser. 1 +
/* now comes another 1 */
1
binding let <var> = <value> in
<scope>
Assigns the value of var-value to the name var-name. This binding is available in the <scope> expression. let x = 4 + 5 in
x * 2
conditional if <cond>
then <if-branch>
else <else-branch>
Evalutes the expression cond. If its value is true, the if-branch will be evaluated, otherwise the else-branch. if x > 2
then "hello"
else "world"
lambda (<p-name> : <p-type>) =>
<lambda-implementation>
A lambda-expression is an anonymous function object. The parameters of the lambda are defined before the arrow (if there is only one parameter, the brackets can be omitted), while the method stub of the lambda, which may contain the parameters as identifiers, is defined after the arrow.
If the parameter types can be inferred by the environment, they can be omitted.
let addition =
(a:Number, b:Number) =>
a + b in
addition(2,3)
get-whereis get <type> whereis <role> This construct enables the reverse navigation through the SocioCortex data model. For example, if a type Employee refers to Department by the relation Location, one can navigate from the Department object d to corresponding Employee objects via d.get Employee whereis Location. (For examples see here)
enclosed identifier '<some identifier>' SocioCortex allows identifiers with special characters (e.g., entity type or attribute names with whitespaces). When referring to those elements, their names have to be enclosed by single quotation marks (‘). 'Operand 1' + op2

Type Checking and Type Casting

In some cases it might by necessary to check an object’s type at runtime. For that purpose, MxL provides the type checking construct <object> is <type>, whereas the following table lists some exemplary applications:

Exemplary Expression Result
"Hello World" is String false
[1,2,3] is Sequence true
[1,2,3] is Sequence<Number> true
[1,2,3] is Sequence<String> false
{s:"hello", n:1} is Structure true
{s:"hello", n:1} is Structure<s:String,n:Number> true
{s:"hello", n:1} is Structure<s:String> true
{s:"hello", n:1} is Structure<s:Number> false
((n:Number) => n + 1) is Function<Number,Number> true
date("01.01.2000") is Date true
"Hello World" is Object true

While the type checking construct evaluates to either true or false, the down casting construct <object> as <type> casts an object to the given type. If the object is not of the given type, this construct would throw an exception. The following table lists some exemplary applications:

Exemplary Expression Result
"Hello World" as String "Hello World"
"Hello World" as String Error: Cannot cast String to Number