# Variables Manipulation

## Basic Mathematical Operations

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

``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”

Alternatively, interpollating strings can be used.

Interpollating strings are declared with the “\$” sign and should be followed by quotes. All variables used within the strings, require to be within percentage signs “%%”

The prevous example using interpollating strings would look as follows.

``````set TextVar1 to 'Monday'
set TextVar2 to 'Friday'
set duration to \$"%TextVar1%  to %TextVar2%"``````

### 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 indexed as “charlist“.

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

In a string containing the letters from A to I in variable TextVar:

``set TextVar to "ABCDEFGHI"``

Base A B C D E F G H Ι
1-based 1 2 3 4 5 6 7 8 9
0-based 0 1 2 3 4 5 6 7 8
• [2:] would return “CDEFGHI”
•  would return “C”
• [:2] would return “AB”
• [2:4] would return “CD”

### 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[:3]``````

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``````

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``````

## Comparison Operators

The comparison operators used are the following.

Notation Operation
= Equal
!= Not equal
<> Not equal
< Less
<= Less than or equal
> More
>= More than or equal
in Is included
not in Is not included

### Text Comparison

Two string values can be compared using the comparison operators. The below comparison will return true as indeed Adam is before Bob in the Alphabet.

``set Names to "Adam" < "Bob"``

### Date Comparison

Two dates can be compared using the comparison operators. The below comparison will return False as the 12nd of November is before the 14th of December.

``set Dates to d"2019-11-12" > d"2019-12-14"``

### 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 below 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``````

## Logical Operators

Notation Operation
OR When one of many conditions meet
AND When all conditions meet
XOR When only one of two conditions meet
NOT When a condition does not meet

### Examples

In this example, the variable A is True while variable B is False.

Using the OR operator, the LogResult will be True as at least one of the two values is True.

``````set A to True
set B to False
set LogResult to A OR B``````

Using the AND operator, the LogResult will be False as at least one of the two values is False.

``````set A to True
set B to False
set LogResult to A AND B``````

Using the XOR operator, the LogResult will be True as only one of the two values is True.

``````set A to True
set B to False
set LogResult to A XOR B``````

Using the NOT operator, the LogResult will be False as A’s initial value it True.

``````set A to True
set B to False
set LogResult to NOT A``````