Automate

Automate

Make your phone or tablet smarter with automation

Get it on Google Play

Expressions & operators

Expressions can be used as input arguments in blocks. For example, use the Expression true block to check if an expression evaluate to true.

To write an expression, switch to “expression mode” by tapping the strike through “fx” icon within an input argument field, tap it again to return to “constant mode”.

Expressions

An expression is any valid unit of code that resolves to a value. Automate has the following expression categories:

Operators

Automate has the following types of operators:

Arithmetic operators

Arithmetic operators take numerical values as their operands and returns a single numerical value. Any non-numerical operand is first converted (coerced) to a number. If all operands are of the bigint type then the result is as well. Mixing bigint and number operands will fail, use the to number operator or bigint function to explicitly use either.

Addition +

A binary operator; 1 + 2 returns 3.

Subtraction -

A binary operator; 2 - 1 returns 1.

Multiplication *

A binary operator; 2 * 2 returns 4.

Division /

A binary operator; 10 / 3 returns 3.333. 10 / 0 returns Infinity. 10n / 3n returns 3n (bigint). 10n / 0n fails.

Integer division //

A binary operator; 10 // 3 returns 3. 10 // 0 returns Infinity. 10n // 0n fails.

Remainder %

A binary operator that returns the remainder of dividing the two operands; 12 % 5 returns 2. 12 % 0 returns NaN. 12n % 0n fails.

Negate -

A unary prefix operator that returns the negation of its operand; -(-5) returns 5.

Bitwise operators

Bitwise operators take numerical values as their operands and returns a single numerical value. Any non-numerical operand is first converted (coerced) to a number. A number operand is treated as a set of 32 bits. If all operands are of the bigint type then the result is as well. Mixing bigint and number operands will fail, use the to number operator or bigint function to explicitly use either.

Bitwise AND &

A binary operator that returns a one in each bit position for which the corresponding bits of both operands are ones; 0b0101 & 0b0011 returns 0b0001.

Bitwise OR |

A binary operator that returns a one in each bit position for which the corresponding bits of either or both operands are ones; 0b0101 | 0b0011 returns 0b0111.

Bitwise XOR ^

A binary operator that returns a one in each bit position for which the corresponding bits of either but not both operands are ones; 0b0101 ^ 0b0011 returns 0b0110.

Bitwise NOT ~

A unary operator that inverts the bits of its operand; ~0b1 returns 0xFFFFFFFE. ~0b1n returns -1n (bigint).

Left bit shift <<

A binary operator that shifts the bits to the left; 0b10010111 << 1 returns 0b00101110.

Right bit shift >>

A binary operator that shifts the bits to the right, keeping the sign of a negative number; 0b10010111 >> 1 returns 0b11001011.

Zero-fill right bit shift >>>

A binary operator that shifts the bits to the right, without keeping the sign of a negative number; 0b10010111 >>> 1 returns 0b01001011. Fails with bigint.

Comparison operators

A comparison operator compares its two operands and returns a logical value based on whether the comparison is true or false. The operands can be numeric or text. Numeric comparison of number and bigint (mixing) operand types is allowed, unlike arithmetic operators, but not of other value types, i.e. comparing number with text always returns 0. null compares as less to a non-null value. The return type is always number, either 1 for true or 0 for false. Texts are compared on case-sensitive lexicographical order.

Equal =

A binary operator that returns 1 if the operands are equal; 3 = 3 returns 1.

Not equal !=

A binary operator that returns 1 if the operands are not equal; 3 != 3 returns 0.

Greater than >

A binary operator that returns 1 if the left operand is greater than the right operand; 2 > 2 returns 0.

Greater or equal >=

A binary operator that returns 1 if the left operand is greater than or equal to the right operand; 2 >= 2 returns 1.

Less than <

A binary operator that returns 1 if the left operand is less than the right operand; 2 < 2 returns 0.

Less or equals <=

A binary operator that returns 1 if the left operand is less than or equal to the right operand; 2 <= 2 returns 1.

Logical operators

Automate does not have a value type nor literals for true or false, instead the following are considered false:

All other values are considered true.

Logical AND &&

A binary operator that returns left operand if it evaluate to false, otherwise right operand is returned; 2 && 3 returns 3.

Logical OR ||

A binary operator that returns left operand if it evaluate to true, otherwise right operand is returned; 2 || 3 returns 2. null || 0 || "Hi" returns "Hi".

Logical NOT !

A unary prefix operator that returns 1 if the operand evaluate to false, otherwise 0 is returned; !3 returns 0.

Special operators

To number +

An unary prefix operator that returns the operand converted to a number; +2n returns 2. +"2" returns 2. +"0xFF" returns 255.

To text ++

An unary prefix operator that returns the operand converted to text; ++2 returns "2".

Text concatenation ++

A binary operator that returns the two operands concatenated into a text; "Good"++"bye" returns "Goodbye", 2++2 returns "22".

Conditional ? :

A ternary operator, operand ? operand : operand; If the first operand evaluate to true the seconds operand is returned, otherwise the third operand is returned; 2=2 ? "two" : "other" returns "two".

Length #

An unary prefix operator;

  • If the operand is a text, returns the number of characters; #"Hi" returns 2.
  • If the operand is an array, returns the number of elements; #[1,2] returns 2.
  • If the operand is a dictionary, returns the number of entries; #{"a":1,"b":2} returns 2.
  • Otherwise zero is returned.

Subscript [ ]

A binary operator, operand[operand];

  • If the first operand is a text, returns the Unicode character code at the index of the second operand; "Hi"[1] returns 105.
  • If the first operand is an array, returns the element at the index of the second operand; ["a","b","c"][1] returns "b".
  • If the first operand is a dictionary, returns the value mapped to the key of the second operand; {"a":1,"b":2}["b"] returns 2.
  • Otherwise null is returned.

Constant expression

A constant expression can only include null, and literals for number, bigint, text, array and dictionary.

Note! This documentation is also accessible within the app from Help & feedback menu.