Inhaltsverzeichnis

Operators

Genesys offerers all operations you know from the well known languages. But some of them work a little bit different than you know them. Genesys use two concepts of operators. First there are the infix operators you know from C, Java and C#, like +, « or &&. In C++ you also know Prefix operators, like * to dereference or & to create a reference. Genesys does not have any prefix-operations. But there are Postfix-Operations with a special feature: You can use them combined with previous infix- or postfix operators. You will learn about this in the first operator chapter „comparing operators“.

Additionally you have to know that Genesys does explicitly not have an operator '='. To assign a value you have to use the colon (':'), to assign inline code please use (':='). To compare you can use the compare operation like you know them in C or Java ('=='). Due to this there will be no need to suspect a '='-operation within a if-statement to be a mistyped comparison. Either it is a comparison (with '==') or it is an assignment (with ':') - a '=' is wrong.

Assigning a value to a variable

First we see how to define a variable. An unknown identifier ('a') will derive all properties from a type. So we say 'a is int' to define a as in instance of int.

a is int;     // corresponds to int a; in C or Java.

a : 4;        // corresponds to a = 4;

To shorten this you also can use int with its constructor:

a is int(4);  // corresponds to int a(4) in C++

The result of 'a is int' is an integer variable. You can assign a value to an variable:

a is int:4;   // corresponds to int a = 4; in C/C++.

As you see, there are more or less equivalent possibilities to get a variable with a defined value.

Comparison Operations

As you already learned you can compare values with the '=='-Operation. The result is a value of the type 'bool'. So it's true or false.

boolean is bool;

boolean : 1 == 2   // corresponds to boolean = 1 == 2; in C++

The result is false, because 1 and 2 are not equal. To reverse a boolean result you use the prefix operator '!'. You can try like this:

boolean is bool;

boolean : (1 == 2)!;  // corresponds to boolean = !(1 == 2); in C++

Or you can combine a infix with a postfix operator. Note that these is a combination of two independent operators instead of one operator:

boolean is bool;

boolean : 1 ==! 2;    // corresponds to boolean = 1 != 2; in C or Java

What is the difference between a shorter operation like '!=' and a combined operator like '==!'. You can put every postfix operator behind every value or operation you like. You will see the advantages in the chapter for the 'toString()'-operator.

Before this, let us compare values. You can compare them to be greater than ('>'), smaller than ('<'), greater or equal ('>=') or smaller or equal ('⇐').

b is bool;

b : 1 >  2;           // corresponds to b = 1 >  2; in C/Java
b : 1 >= 2;           // corresponds to b = 1 >= 2; in C/Java
b : 1 <  2;           // corresponds to b = 1 <  2; in C/Java
b : 1 <= 2;           // corresponds to b = 1 <= 2; in C/Java

You also have learned that you can negate operators with the '!'-postfix. So you can negate the result of a '>'-operator by combining it with a '!'-postfix

b is bool;

b : 1 >!  2;          // corresponds to b = !(1 >  2); in C/Java
b : 1 >=! 2;          // corresponds to b = !(1 >= 2); in C/Java
b : 1 <!  2;          // corresponds to b = !(1 <  2); in C/Java
b : 1 <=! 2;          // corresponds to b = !(1 <= 2); in C/Java

So >! is equal to ⇐, >=! is equal to <, <! is equal to >= and ⇐! is equal to >.

Usually you should use the simples way of expressing yourself, which usually is > instead of ⇐!. But if you want to emphasize that a value must be not smaller or equal or you want to express that you want the negated value of '⇐', you can easily do this with '⇐!'.

The 'asString()'-Operation

With Genesys strings are a build-in data type. Everything in quotes are strings. So let us define and print a string:

hw is string( "Hello World" );

print hw;

Now let us print a value of a different data type:

a is int( 4711 );

print a;

This won't work because print only prints strings. Genesys is a highly restrictive programming language that means that you have to express exactly what you want. The representation of an integer is not human readable. We usually want to the value of 4 in decimal system. But an integer is only a value and has no information about the numbering system you prefer. With Java you can call the 'toString()' Method.

int a = 4711;
 
System.out.println( Integer(a).toString() );

With Genesys you got the default string representation with the prefix operator '$'.

a is int( 4711 );

print a$;

Again: you can put a postfix operator behind every value or operator:

print "1 >=  2 : ", 1 >=$ 2, "\n";   // => "1 >=  2 : false"
print "1 ==  2 : ", 1 ==$ 2, "\n";   // => "1 ==  2 : false"
print "1 ==! 2 : ", 1 ==!$ 2, "\n";  // => "1 ==! 2 : true"

Maybe this looks a little bit strange for the beginning, but isn't 1 ==$ 2 easier to understand than Boolean( 1 == 2 ).toString()?

Math Operators

Genesys offers here the usual stuff.

print "1 + 2 : ", 1 +$ 2, "\n";   // => "1 + 2 : 3"
print "1 - 2 : ", 1 -$ 2, "\n";   // => "1 - 2 : -1"
print "1 * 2 : ", 1 *$ 2, "\n";   // => "1 * 2 : 2"
print "1 / 2 : ", 1 -$ 2, "\n";   // => "1 / 2 : 0"
print "1 % 2 : ", 1 %$ 2, "\n";   // => "1 % 2 : 0"

Numbers without a point have the smallest bit with they need. 100 is a byte, 10000 is short, 1000000 is int. The result of an operation is the type which is expected. If you expect a byte 255+1 results in 0. If you expect a short it's 256. If you combine an integer and floating point data type the result will be the involved floating point type. Division with integers will result in an integer division and the result will have the same type as the first parameter. Same for the modolu-operation. The resulting data type of addition, subtraction and multiplication is the greater type of the operands.