This is a list of all keywords in the Xill language, with an example code snippet. Almost all keywords are explained in more detail on another page. Click the accompanying link or use the search function on top.
use (as)
The use
keyword allows a developer to declare usage of a Xill package. This is required to make a package accessible for the script. Optionally you can use the as
keyword to assign an alias to the reference.
use Database as db; var resultset = db.query("SELECT * FROM table");
var
var variable = "value";
if (else)
if( i>max_value ) { break; } else { continue; }
while
while(i<max_value) { doSomething(); i += 1; }
(private) function
function giveMeSomething() { return "something"; } private function doSomething() { // this function can only be called from within the same robot. }
return
function giveMeSomething() { return "something"; }
foreach
foreach(index, element in list) { doSomething(element); }
break
When executed, breaks out of the current loop, function or robot (whatever is the deepest context).
if( i > max_value ) { break; } else { continue; }
continue
Breaks the current iteration in a loop, without breaking the loop. The next iteration (if there is one) will start immediately.
foreach(element in list) { if( i > max_value ) { break; } else { continue; } }
include
Used to include functions from other (library) files.
include extraction.extract_images;
callbot
var message = "Hello World"; callbot("temp/PrintString.xill",message);
This built-in function will run the robot located at the given (relative) path. The optional parameter can be used in the called robot with the argument
keyword.
argument
This is used for naming the variable that was given to the robot by calling it. So, in the above example, PrintString.xill can 'capture' the value of message
in the variable here named messageArgument
.
argument messageArgument; System.print(messageArgument);
runBulk
This will call a robot, like callbot (see above), but can take a list of arguments instead of just one, and call multiple instances of the robot in parallel, passing one element for every call.
use System; System.print("Starting..."); var count = runBulk("runBulk1.xill", ["project","publication","news","person","event"], {"maxThreads":3, "stopOnError":"yes"}); System.print("Total amount of instances run: "::count);
This will run the robot 'runBulk1.xill' five times. Once with 'project' as argument, once with 'news' as argument, etcetera, but not necessarily in this order. Three of these instances will be run at the same time (the maxThreads
parameter).
map
This built-in function can execute a function for each element of a collection. In many cases this can replace a foreach
loop. If the function returns a result (which is optional), then the result of the map call will be a new collection with the original values replaced by the results of the function.
var list = [1, 2, 3]; var newList = map<someFunction>(list);
The function (in this example named someFunction
) that is used by a map must have one or two parameters: one for the values in the collection and optionally another one for the keys. If two parameters are provided, the left one will be the key and the right one the value.
filter
This built-in function filters a collection based on a function. The result is a new collection variable that contains only the elements for which the function returned true.
var allNumbers = [ 5, -2, 0, 8, -3 ]; var positiveNumbers = filter<isPositive>(allNumbers); // positiveNumbers is now [ 5, 0, 8 ]. function isPositive(num) { return num >= 0; }
ATOMIC, LIST, OBJECT
Every variable is of one of these three types. You can compare a variable to one of them with the function System.typeOf
.
if( System.typeOf(result) != OBJECT ) { System.out("result doesn't have the expected format","debug"); }
These are special variables. Their value is always the string value of their name.
null and NaN
These are also special variables. null
probably needs little introduction. This value could, for instance, be the result of a query (in case there is no result) or a function that did not return anything.
queryresult = Database.query("SELECT * FROM employees WHERE name = '" :: name :: '""); if(queryresult == null) { System.print("We don't have an employee called " :: name); }
NaN
(Not a Number) is the number value of a variable that does not hold a number, and this value will also be the result of a construct that should return a number, but could not. This can happen if you make a programming error like trying to concatenate strings with the +
operator or if your robot tries to divide by zero. In the next example, the two variables would be automatically set and therefore you should take the possibility into account that one or both are zero or null at some point.
var moneyWonPerPerson = prizeMoney / numberOfWinners; if(moneyWonPerPerson == NaN) { System.print("Sorry, there is no information yet about how much money every winner will get"); }