What’s new in SIL 3.0? - Kepler-Rominfo€¦ · What’snew in SIL 3.0? Contact Florin Haszler...

Preview:

Citation preview

What’s new in SIL 3.0?

ContactFlorin HaszlerTel: +40 21 233 10 80Email: florin.haszler@kepler-rominfo.com

www.kepler-rominfo.com

In short…

1. Defining Global Variables

2. Constants

3. Multi-dimensional arrays

4. User-defined structure types

5. Chaining index and field access

6. Additional operators

7. Error handling (try-catch blocks)

Defining Global Values

• Define variables before function definitions

number HOURS_PER_DAY = 8;

number DAYS_PER_WEEK = 5;

function hoursInWeek() {

return HOURS_PER_DAY * DAYS_PER_WEEK;

}

• Create libraries of application-wide values

include “application_constants.incl”;

function hoursInWeek() {

return HOURS_PER_DAY * DAYS_PER_WEEK;

}

Constants

• Declare variables as constants

• Prevents (accidental) modification

const number HOURS_PER_DAY = 8;

const number DAYS_PER_WEEK = 5;

function hoursInWeek() {

return HOURS_PER_DAY * DAYS_PER_WEEK;

}

DAYS_PER_WEEK = 4; // error

Constants (2)

• Declare function parameters as constants

function arrayContains(const string [] array,

string element) {

array[0] = element; // no cheating!

return arrayFind(array, element);

}

• Prevent parameters from being modified within function body

Arrays

• SIL 2 only handles one-dimensional arrays

• … so why not more?

string [] arr1 = { “1”, “2” };

string [][] arr2 = { {“1.1”, “1.2”}, {“2.1”, “2.2”} };

• As many dimensions as one can keep track of (32 – can handle more? Let us know)

• Move around entire rows (dimensions)arr2[0] = arr1;

arr2[1] = arr1;

// or

arr2 = { arr1, arr1 }; // bonus feature

Structures

• User-defined structure types

struct Person {

string firstName;

string lastName;

number age;

}

• Structured access to data

• Easy to understand SIL scripts

• Castable from string []

Person p = {“John”, “Doe”, “32”};

Casting Structures

• Two-way casting between structures and arrays

• Casting array -> structure

– Array element type must be castable to any type of field in the structure

• Casting structure -> array

– Every type of field in the structure must be castable to array element type

Indexing

• For arrays:– Indexed by number:

array[1] = value;

– Indexed by keyarray[“key”] = value;

• For structures– Indexed by field name

person[“firstName”] = “John”;

– Access by field nameperson.lastName = “Doe”;

• Chaining teams[“JIRA”].developers[3].firstName

Additional Operators

• Pre-increment: ++i

• Post-increment: i++

• Pre-decrement: --i

• Post-decrement: i—i = 0;

j = i++ + --i + ++i + i--; //2

• Ternary ifreturn condition ? ifTrueValue : ifFalseValue;

Exception Handling

• SIL variables can be thrown as errorsstring err = “Error message”;

throw err;

• try-catch blockstry {

// instructions

} catch <type> var {

// handle error

} catch {

// handle error

}

• If <type> is specified, will only catch SIL objects of the specified type

• If <type> is NOT specified, will catch any exceptions (SIL errors or Java exceptions)

Find out more

• Documentation

http://confluence.kepler-rominfo.com

• Feedback & suggestions

jira-support@kepler-rominfo.com

Recommended