Scripting Types#

Types#

String#

Strings are a series of characters surrounded by quotes.

string_variable: "This is a String variable"

Note

For non-String types, they must be defined as parameters to scripting functions. This is because anything in a variable definition that is not within curly-braces gets evaluated as a String.

We can define Strings within curly-braces by setting them as parameters to a function:

string_variable: >-
  {
    %string('This is a String variable')
  }
string_variable: >-
  {
    %string("This is a String variable")
  }

There are a few ways to make variables that use curly braces more compact, including:

string_variable: >-
  { %string('This is a String variable') }
string_variable: >-
  { %string("This is a String variable") }
string_variable: "{ %string('This is a String variable') }"

In the case that you want to define a string variable that contains both single and double quotes, triple-quotes can be used to avoid closing the String.

string_variable: >-
  {
    %string('''This has both " and ' in it.''')
  }
string_variable: >-
  {
    %string("""This has both " and ' in it.""")
  }

If you want a plain string that contains literal curly braces, you can escape them like so:

string_variable: "This contains \\{ literal curly braces \\}"

Integer#

Integers are whole numbers with no decimal.

int_variable: >-
  {
    %int(2022)
  }
int_variable: >-
  { %int(2022) }
int_variable: "{ %int(2022) }"

Float#

Floats are floating-point decimals numbers.

float_variable: >-
  {
    %float(3.14)
  }
float_variable: >-
  { %float(3.14) }
float_variable: "{ %float(3.14) }"

Boolean#

A type is considered boolean if it spells out True or False, case-insensitive.

bool_variable: >-
  {
    %bool(True)
  }
bool_variable: >-
  { %bool(True) }
bool_variable: "{ %bool(FALSE) }"

Array#

An Array contains multiple types of any kind, including nested Arrays and Maps. Arrays are defined using brackets ([ ]), and are accessed using zero-based indexing.

array_variable: >-
  {
    [
      "element with index 0",
      1,
      2.0,
      [ "Nested Array 3" ]
    ]
  }
element_0: >-
  {
    %array_at(array_variable, 0)
  }
array_variable: >-
  { ["element with index 0", 1, 2.0, ["Nested Array 3"]] }
element_0: >-
  { %array_at(array_variable, 0) }
array_variable: "{ ['element with index 0', 1, 2.0, ['Nested Array 3' ]] }"
element_0: "{ %array_at(array_variable, 0) }"

Map#

A Map is a key-value store, containing mappings between keys and values. Maps are defined using curly-braces ({ }), and are accessed using their keys.

map_variable: >-
  {
    {
      "string_key": "string_value",
      1: "int_key",
      "list_value": [ "elem0", 1, 2.0 ]
    }
  }
string_value: >-
  {
    %map_get(map_variable, "string_key")
  }
map_variable: >-
  { {"string_key": "string_value", 1: "int_key", "list_value": ["elem0", 1, 2.0]} }
string_value: >-
  { %map_get(map_variable, "string_key") }
map_variable: "{ {'string_key': 'string_value', 1: 'int_key', 'list_value': [ 'elem0', 1, 2.0 ]} }"
string_value: "{ %map_get(map_variable, 'string_key') }"

Null#

Null is represented by an empty String, and can be conveyed by spelling out null, case-insensitive.

null_variable: ""
null_variable: >-
  { %string(null) }
null_variable: "{ %string(null) }"

Function Type-Hints#

AnyArgument#

AnyArgument means any of the above Types are valid as input or output to a scripting function.

Note

Strict typing is enforced. For functions that return AnyArgument need to be casted before passing into functions that expect a particular type.

Numeric#

Numeric refers to either an Integer or Float.

Optional#

Optional means a particular scripting function argument can be either provided or not included. For example, the function map_get has an optional default value. Both of these usages are valid:

will_throw_key_does_not_exist_error: "{ %map_get( {}, 'key' ) }"
will_return_default: "{ %map_get( {}, 'key', 'default value' ) }"

Lambda#

Lambda parameters are a reference to a function, and will call that lambda function on the input. In this example,

lambda_array_numeric_to_string: >-
  {
    %array_apply( [ 1, 2, 3, 4], %string )
  }

We apply %string as a lambda function to array_apply, which is called on every element in the input array. The output becomes ["1", "2", "3", "4"].

This example has one input-argument being passed into the lambda. For other lambda-based functions like array_enumerate, it expects the lambda function to have two input arguments. These are denoted using LambdaTwo, LambdaThree, etc within the function spec.

LambdaReduce#

LambdaReduce parameters are a reference to a function that will perform a reduce - an operation that reduces an Array to a single value by calling the LambdaReduce function repeatedly on two elements in the Array until it is reduced to a single value.

In this example,

lambda_reduce_sum: >-
  {
    %array_reduce( [ 1, 2, 3, 4], %add )
  }

We call array_reduce on the input array, using add as the LambdaReduce function. This will reduce the Array to a single value by internally calling

  • reduce-call 1: %add(1, 2) = 3 (first two elements)

  • reduce-call 2: %add(3, 3) = 6 (output from first two and third element)

  • reduce-call 3: %add(6, 4) = 10 (output from first three elements and fourth element)

And evaluate to 10.

ReturnableArguments#

Returnable arguments are used in conditional functions like if, which implies the argument passed into the function is the function’s output. For example,

conditional_function: >-
  {
    %if( True, "Return this if True", "Return this if False" )
  }

is going to return "Return this if True" since the condition parameter is True.