Variables Manipulation

Basic Mathematical Operations

In Robin, the basic mathematical operations can be achieved using the operation characters (+,-,/,*,%)

Addition

set sum to 2+1

Subtraction

set diff to 2-1

Division

set div to 3/2

Multiplication

set prod to 2*3

Modulus

set divident to 26 mod 5

Text Concatenation and Subtraction

In Robin, text can be handled similarly to the way mathematical operations are completed.

Concatenate text variables

To concatenate two text values to one, the plus (+) sign needs to be used. In case there is need to add actual text like spaces, it needs to be in quotes.

set TextVar1 to 'Monday'
set TextVar2 to 'Friday'
set duration to TextVar1+' to '+TextVar2

The value of the duration variable will be “Monday to Friday”

Operations with text

Similar to the concatenation, there can be text subtraction. Using a subtraction, part of a text value can be extracted.

set SubtractText to 'ABCD'-'B'

In this case, the value of the SubtractText variable will be “ACD”.

Indexing and Slicing

Lists, Datatables as well as text, mark each of their items or characters with indexes. To slice text, lists or datatables, indicators of the index to be parsed are required. Note, that the index can be marked using square brackets and the index is always zero based. For example, the 3rd item of the “charlist” list variable, would be indexes as “charlist[2]“.

Notation Description
[4:] From the 5th character or item until the end
[:6] From the beginning until the 7th character or item
[4:6] From the 5th character or item until the 7th

Example

In this example, the variable Date is set to Monday 15th of April in a text format “MON15APR”. The first three letters mark the day name. To extract it, the variable will be sliced from the beginning to the 3rd character.

set date to 'MON15APR'
set dayname to date[:2]

Similarly, below we have a list with the same information. Using the item in index 2 the month name can be extracted.

set date to ['MON',15,'APR']
set monthname to date[2]

List Addition

Using the basic mathematical operations, lists can be merged or subtracted.

For example, list1 with items A,B and D can be combined with list2 that contains items A,C,D and E.

Adding the two lists, the new list will include all items (i.e. A,B,D,A,C,D and E).

set list1 to ['A','B','D']
set list2 to ['A','C','D','E']
set sumlist to list1+list2

List Comparison

Apart from mathematical operations between two lists, Robin allows the comparison between them.

Using the term “in” you can check if a list is part of another list.

Note, that the result in this case will be a boolean value.

In the example used above the value of listpart will be “false”.

set list1 to ['A','B','D']
set list2 to ['A','C','D','E']
set listpart to list1 in list2