Variable Modifiers

Variable modifiers allow you to work directly with a variable, making your code look more logical and easier to follow, as well as taking less time to type out. A variable modifier would look like this:

<variable>.<modifier>(<arguments>);

let int n1 = int 1;
n1 = add(n1, int 3); # n1 = 4

# We can use a variable modifier here instead
let int n2 = int 1;
n2.add(int 3); // n2 = 4

Variable modifiers still execute the original functions (i.e. the above is using the add() function), although we drop the first argument of the function and ensure all other arguments are provided.

In some cases, variable modifiers will also store the result directly to the original variable as well, therefore the following is invalid:

let int n1 = 1;
let int n2 = n1.add(int 3); // Error - n1 = 4, n2 = compile error

//Instead you would do the following
let int n1 = 1;
let int n2 = add(n1, int 3); // n1 = 1, n2 = 4

The following functions are acceptable variable modifiers (ensure the types are correct):

  • add

  • sub

  • mul

  • concat

  • mod

  • div

  • length

  • get

  • pop

  • drop

  • in

  • push

Last updated