Operators

Cherri supports arithmetic and assignment operators on numeric values and variables.

Table of contents

  1. Arithmetic
    1. Action calls
  2. Assignment
    1. Array append
  3. Conditional and logical operators

Arithmetic

Arithmetic expressions operate on numbers and produce a result that can be stored in a constant or variable.

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (remainder)
const sum = 10 + 5
const difference = 10 - 5
const product = 10 * 5
const quotient = 10 / 5
const remainder = 10 % 3

Both operands can be variables:

@a = 10
@b = 3
const result = @a % @b

Future release

An expression can start with a variable or a constant, no parentheses needed:

@a = 10
const result = @a % 3
const scaled = result * 2

Parentheses set the order of operations, at the start of an expression or after an operator.

@a = 10
const grouped = (@a + 5) * 2
const groupedAfterOperator = 2 * (@a + 5)

Expressions can be used wherever a value is expected, including action arguments, array and dictionary items, and repeat counts.

@a = 10
const doubled = number(@a * 2)
@values = [@a + 1, @a + 2]
repeat i for 3 + 1 {
    show("{i}")
}

An expression used inside another statement is added as its own action just before that statement, and the statement uses that action’s output. One operation between two operands uses a Math action. Anything longer uses a Calculate Expression action.

Expressions also work as conditional values:

@a = 10
if @a + 1 > 10 {
    show("Greater")
}

Action calls

Future release

In a future release, an action call can be used as an operand. The action runs first and its output is used in the expression:

@items = list("a", "b", "c")
const nextCount = count(@items) + 1

Assignment

Assignment operators modify a variable in place.

Operator Description
= Set value
+= Add to
-= Subtract from
*= Multiply by
/= Divide by
@n = 10
@n += 5
@n -= 2
@n *= 3
@n /= 2

Future release

The value can also be a variable, an expression, or an action call:

@n = 10
@a = 3
@items = list("a", "b")
@n += @a
@n -= 1 + 1
@n += @n * 2
@n *= count(@items)

Array append

When used on an array variable, += appends an item rather than performing numeric addition.

@items: array
@items += "first"
@items += "second"

Conditional and logical operators

Conditional operators (==, !=, contains, >, etc.) and logical operators (&&, ||) are used in if statements and are covered in Control Flow.


Copyright ©. Distributed under the GPL-2.0 License. Siri Shortcuts and Mac are registered trademarks of Apple Inc. Apple is not involved in this project in any way. Do not contact Apple Support unless you are having an issue with the Shortcuts app itself.