Skip to content

ELENA Code Snippets

Aleksey Rakov edited this page May 22, 2023 · 12 revisions
//************************************************************************
//* Console:                                                             *
//************************************************************************
console.write: "Hello World";      // output string in console
console.writeLine: "Hello World";  // output string in console followed by 
                                   // the line terminator

//************************************************************************
//* Assignment:                                                          *
//************************************************************************
var x := 4;                        // new variable
x := 5;                            // assignment
x := new Object();                 // allocated instance of a class

//************************************************************************
//* Constants:                                                           *
//************************************************************************
var b := true;                     // true constant
b := false;                        // false constant
b := nil;                          // nil object constant
x := 1;                            // integer constants
x := 3.14r;                        // float constants
x := -1;                           // negative constants
x := "Hello";                      // string constant
x := "I""m here";                  // single quote escape
x := new int[] {3, 2, 1};          // array constants
x := new object[]{"abc", 2, 2.3r}; // mixing of types allowed

//************************************************************************
//* Booleans:                                                            *
//************************************************************************
x := 1;
var y := 2;
b := (x == y);                     // equals
b := (x != y);                     // not equals
b := (x.equalReference(y));        // identical
b := (x > y);                      // greater than
b := (x < y);                      // less than
b := (x >= y);                     // greater than or equal
b := (x <= y);                     // less than or equal
b := b.Inverted;                   // boolean not
b := (x < 5).and(y > 1);           // boolean and
b := (x < 5).or(y > 1);            // boolean or
b := (x < 5) && (y > 1);           // boolean and (short-circuit)
b := (x < 5) || (y > 1);           // boolean or (short-circuit)
b := (x < 5).xor(y > 1);           // test if one true and other false

//************************************************************************
//* Arithmetic expressions:                                              *
//************************************************************************
x := 0;
x := 6 + 3;                        // addition
x := 6 - 3;                        // subtraction
x := 6 * 3;                        // multiplication
x := 5 / 3;                        // integer divide
x := 5.mod:3;                      // integer remainder
x := 5.realDiv:3;                  // division with float result
x := -5;                           // unary minus
x := 5.Negative;                   // negate receiver
x := 6 * 3.1r;                     // auto convert to float
x := 5.power:2;                    // power function

//************************************************************************
//* Bitwise Manipulation:                                                *
//************************************************************************
x := 0;
x := 0FFh.band: 0Fh;                // and bits
x := 0F0h.bor: 0Fh;                 // or bits
x := 0FFh.bxor: 0Fh;                // xor bits
x := 0FFh.BInverted;                // invert bits
x := 0Fh.shiftLeft:-4;             // left shift
x := 0F0h.shiftRight:4;            // right shift
b := 0FFh.allMask:0Fh;             // test if all bits set in mask set in receiver
b := 0FFh.anyMask:0Fh;             // test if any bits set in mask set in receiver