HOOKSCRIPTv0.9.1

EXPRESSION OPERATORS

In HookScript, you can use several operators for performing calculations on your expressions. The allowed operators are dependent on your data type, with the following operators currently supported.

Comments

  • //: two forward slashes allow you to comment out your text, so the evaluator will ignore any text that comes after two forward slashes on that line

Prefix Operators

  • ! (negation): allows you to negate the value of a boolean expressions (e.g., !true == false)
  • - (reverse): syntatic sugar for multiplying an int or float by -1

Postfix Operators

  • ++ (increment): syntactic sugar for adding 1 to an int or float
  • -- (decrement): syntactic sugar for subtracting 1 from an int or float

Arithmetic Operators

  • + (addition): allows you to add two int or float types, or concatenate text types
  • - (subtraction): allows you to substract two int or float types
  • * (multiplication): allows you to multiply two int or float types
  • / (division): allows you to divide two int or float types
  • % (modulo): allows you to return the remainder when dividing int types

Shorthand Assignment Operators

  • += (add): allows you to add value to a variable
  • -= (subtract): allows you to subtract a value from a variable
  • *= (multiply): allows you to multiply a variable by the value
  • /= (divide): allows you to divide a variable by the value

Comparison Operators

  • == (equals): allows you to compare two int, float, bool, or text types
  • != (equals): allows you to compare two int, float, bool, or text types
  • > (greater than): allows you to compare two int, float, or text types
  • < (less than): allows you to compare two int, float, or text types
  • <= (less than or equal to): allows you to compare two int, float, or text types
  • >= (greater than or equal to): allows you to compare two int, float, or text types
  • in (in): returns true or false if a list, dict, record, or text contains the value, key, or subtext

Built-in Functions

  • len(object): returns an int that is the number of characters in a text value, the number of elements in an array value, or the number of elements in a map value
  • print(...objects): prints the provided object(s) to the console; returns the number of bytes written to the console
  • typeof(object): returns the underlying type of an object as text
  • source(path): pulls data into HookScript for processing

Examples:

10 > 8 // returns true
10 < 8 // returns false
10 >= 10 // returns true
10 <= 9 // returns false
10 + 2 // returns 12
10 - 2 // returns 8
10 / 5 // returns 2
10 * 5 // returns 50
"hello" + " world" // returns "hello world"
len("hello world") // returns 11
len(["a", "b", "c"]) // returns 3
!true // returns false
-(10 * 2) // returns -20
print("hello") // prints "text" to the console
print(typeof("hello")) // prints "text" to the console
print("ll" in "hello") // returns true
print(40 in [10, 20, 30]) // returns false
print("name" in { name: "PJ", age: 7 }) // returns true

Loading Playground

Built with in Halifax, Nova Scotia by JW