Dynamic Functions

While the mathematical engine provides the foundation for all numerical computation, Dynamic Functions are the specialized tools that unlock advanced data manipulation, string processing, and complex logic that goes beyond simple math. Every dynamic function is prefixed with a dollar sign ($) to distinguish it from mathematical functions.

These functions are the heart of the EasyEdge Operations Engine data transformation capabilities. They allow you to parse structured text, build complex strings, compare values, and even perform cryptographic hashing, all within a single, unified environment.


Main Concepts of Dynamic Functions

Before exploring the individual functions, it is essential to understand the core principles that govern all of them.

Argument Types

Dynamic functions are versatile and can accept several types of arguments, which can be mixed and matched as needed:

  • Operand: A single lowercase letter (a to z) that references a system object. The function will use the current value of that object when it executes.

  • String Literal: A constant text value enclosed in single quotes (e.g., 'hello world', 'json', 'ERR:', '1E').

  • Numeric Literal: A static number (e.g., 42, 3.14, -10, 0x1E).

  • Nested Expression: The result of any other mathematical expression or dynamic function. This powerful feature allows for creating deeply nested, recursive logic (see Section 5).

Return Types: The Bridge Between Worlds

Dynamic functions can return different types of data, primarily numeric or string. This is the key to the symbiosis between the two engines:

  • Functions returning numbers (e.g., $length, $compare, $indexOf) are designed to be used directly within mathematical expressions. Their output can be used for calculations, comparisons, or as input to other mathematical functions.

  • Functions returning strings (e.g., $concat, $upper, $substring) are used to build, format, and manipulate text.

Understanding which function returns which type of data is crucial for building powerful, hybrid expressions, as detailed in page The Power of Symbiosis: Fusing Math and Functions.


Function Reference

The following sections provide a detailed reference for every available dynamic function, organized by category.

Core & Structural Functions

These functions form the backbone of data transformation and logical flow. They are used for parsing complex data, constructing new strings from multiple parts, and making decisions.

$concat(arg1, arg2, ...)

Concatenates two or more arguments into a single string. Any numeric arguments are automatically converted to their string representation.

Returns: A new string representing the concatenation of all arguments.

Examples:

  • $concat(a, ' ', b) → If a is 'John' and b is 'Doe', the result is 'John Doe'.

  • $concat('Alert: Temp at ', c, ' exceeds limit.') → If c is 95.5, the result is 'Alert: Temp at 95.5 exceeds limit.'.

$format(formatStr, arg1, ...)

Constructs a formatted string using sprintf-style format specifiers, allowing for precise control over the representation of numbers and the inclusion of variables within a string.

Returns: A new, formatted string.

Example:

  • $format('Sensor %s has value %.2f', a, b) → If a is 'S01' and b is 19.5, the result is 'Sensor S01 has value 19.50'.

$parse(contentType, source, path)

Parses a structured string (like JSON or XML) and extracts a specific value using a path query. This is a critical function for interoperability with systems that communicate using structured data formats.

Parameters:

  • contentType: [Operand | String Literal] - The format of the source string. Supported: 'json', 'xml', 'csv'.

  • source: [Operand | String Literal] - The structured string to be parsed.

  • path: [Operand | String Literal] - The query path to the desired value (e.g., JSONPath '$.sensor.value').

Returns: The extracted value, which can be either a number or a string, depending on the data at the specified path.

Examples: (Assume operand a contains: {"metrics":{"temp":25.5, "unit":"C"}})

  • $parse('json', a, '$.metrics.temp') → Result: 25.5 (numeric).

  • $parse('json', a, '$.metrics.unit') → Result: 'C' (string).

$regex(source, pattern, group)

Applies a regular expression to a source string and extracts a specific capture group. This provides powerful pattern-matching capabilities for unstructured or semi-structured text.

Parameters:

  • source: [Operand | String Literal] - The string to search within.

  • pattern: [Operand | String Literal] - The regular expression pattern. Note that backslashes must be escaped (e.g., \\d for a digit).

  • group: [Operand | Numeric Literal] - The capture group to return. 0 represents the entire match, 1 is the first group (...), and so on.

Returns: A string containing the text from the specified capture group.

Example: (Assume operand b contains: 'Firmware v1.2.3-beta')

  • $regex(b, 'v([0-9]+\\.[0-9]+\\.[0-9]+)', 1) → Result: '1.2.3'.

$switch(input, val1, res1, ..., defaultRes)

Evaluates an input value against a series of cases and returns the corresponding result. This is the primary tool for implementing conditional logic that results in non-numeric outputs (like strings) and serves as the engine's "IF" statement for strings.

How it Works: The input argument is evaluated first. This is frequently a mathematical or relational expression that results in a number (e.g., 1.0 for true, 0.0 for false). The $switch function then compares this result to value1, value2, etc. When a match is found, it returns the corresponding result. If no match is found, it returns the defaultResult.

Returns: The value of the matched result argument.

Examples:

Simple Status Code Translation:

  • $switch(a, 0, 'OK', 1, 'Warning', 2, 'Error', 'Unknown') → If a is 1, this returns 'Warning'.

Conditional String Generation (The "IF" for Strings):

  • Scenario: We want to return the string "High Temperature Alert" if sensor a is greater than a threshold b, otherwise return "Nominal".

  • Computation String: $switch(a > b, 1, 'High Temperature Alert', 'Nominal')

  • Breakdown:

  1. The mathematical engine first evaluates the expression a > b.

  2. If a is greater than b, the expression returns the numeric value 1.0.

  3. The $switch function receives 1.0 as its input, matches it to the case 1, and returns the string 'High Temperature Alert'.

  4. If a is not greater than b, the expression returns 0.0. The $switch finds no matching case and returns the default value, 'Nominal'.

String Manipulation & Transformation

This category includes functions for cleaning, modifying, and reshaping strings.

$capitalize(string)

Converts the first character of a string to uppercase and the rest to lowercase.

Returns: A new string.

Example: $capitalize('aLARM') → 'Alarm'

$lower(string)

Converts all alphabetic characters in a string to lowercase.

Returns: A new string.

Example: $lower('WARNING') → 'warning'

$padEnd(string, length, [char])

Pads the end (right side) of a string with a specific character until it reaches a total length. If the string is already longer than the specified length, it is returned unchanged.

Parameters:

  • length: [Operand | Numeric Literal] - The desired final length of the string.

  • char (Optional): [Operand | String Literal] - The character to use for padding. Defaults to a space (' ').

Returns: A new, padded string.

Example: $padEnd('v1.2', 8, '0') → 'v1.20000'

$padLeft(string, length, [char])

Pads the start (left side) of a string with a specific character until it reaches a total length. If the string is already longer than the specified length, it is returned unchanged.

Parameters:

  • length: [Operand | Numeric Literal] - The desired final length of the string.

  • char (Optional): [Operand | String Literal] - The character to use for padding. Defaults to a space (' ').

Returns: A new, padded string.

Example: $padLeft(a, 5, '0') → If a is 123, returns '00123'.

$removePrefix(string, prefix)

Removes a prefix from a string, if it exists. The comparison is case-sensitive.

Returns: A new string without the prefix. If the prefix is not found, the original string is returned.

Example: $removePrefix('SN-12345', 'SN-') → '12345'

$removeSuffix(string, suffix)

Removes a suffix from a string, if it exists. The comparison is case-sensitive.

Returns: A new string without the suffix. If the suffix is not found, the original string is returned.

Example: $removeSuffix('data.tmp', '.tmp') → 'data'

$repeat(string, count)

Repeats a string a specified number of times.

Parameters:

  • count: [Operand | Numeric Literal] - The number of times the string should be repeated.

Returns: A new string with the content repeated.

Example: $repeat('-', 10) → '----------'

$replace(source, find, replace)

Replaces all occurrences of a substring with another. The comparison is case-sensitive.

Parameters:

  • source: The original string.

  • find: The substring to be replaced.

  • replace: The string to insert in place of find.

Returns: A new string with all replacements made.

Example: $replace('2025/07/29', '/', '-') → '2025-07-29'

$replaceFirst(source, find, replace)

Replaces only the first occurrence of a substring. The comparison is case-sensitive.

Parameters:

  • source: The original string.

  • find: The substring to be replaced.

  • replace: The string to insert in place of find.

Returns: A new string with only the first replacement made.

Example: $replaceFirst('a-b-c-d', '-', ':') → 'a:b-c-d'

$split(string, delimiter, index)

Splits a string by a delimiter and returns the element at a specified index.

Parameters:

  • delimiter: The string to use as a separator.

  • index: [Operand | Numeric Literal] - The zero-based index of the element to return.

Returns: A new string containing the specified element.

Example: $split('2024;S01;22.5', ';', 2) → '22.5'

$substring(string, start, [length])

Extracts a portion of a string.

Parameters:

  • start: [Operand | Numeric Literal] - The zero-based index at which to begin extraction.

  • length (Optional): [Operand | Numeric Literal] - The number of characters to extract. If omitted, extracts to the end of the string.

Returns: A new string.

Example: $substring('SN-ABC-123', 3, 3) → 'ABC'

$titleCase(string)

Converts the first character of each word in a string to uppercase.

Returns: A new string.

Example: $titleCase('high pressure alert') → 'High Pressure Alert'

$trim(string)

Removes whitespace characters (spaces, tabs, newlines) from both the beginning and end of a string.

Returns: A new string with leading and trailing whitespace removed.

Example: $trim(' active ') → 'active'

$trimEnd(string)

Removes whitespace characters from the end (right side) of a string.

Returns: A new string with trailing whitespace removed.

Example: $trimEnd(' OK ') → ' OK

$trimStart(string)

Removes whitespace characters from the beginning (left side) of a string.

Returns: A new string with leading whitespace removed.

Example: $trimStart(' OK ') → 'OK '

$upper(string)

Converts all alphabetic characters in a string to uppercase.

Returns: A new string.

Example: $upper('error') → 'ERROR'

Search, Analysis & Comparison

This set of functions inspects strings and returns a numeric result, making them perfect for use in mathematical expressions and conditional logic.

$compare(string1, string2, [ignoreCase])

Compares two strings lexicographically. This is the ideal way to compare strings within the mathematical if() function or a $switch.

Parameters:

  • ignoreCase (Optional): [Boolean Literal] - true to perform a case-insensitive comparison. Defaults to false.

Returns: -1 if string1 < string2, 0 if they are equal, 1 if string1 > string2.

Example: if($compare(a, 'OK', true) == 0, 1, 0)

$contains(string, substring, [ignoreCase])

Parameters:

  • ignoreCase (Optional): [Boolean Literal] - true for a case-insensitive search. Defaults to false.

Returns: 1.0 (true) if the substring is found, 0.0 (false) otherwise.

Example: $switch($contains(a, 'fault', true), 1, 'Error Log', 'Normal Log')

$count(string, substring)

Counts the number of non-overlapping occurrences of a substring.

Returns: A number representing the total count.

Example: $count('1,2,3,4,5', ',') → 4

$endsWith(string, suffix, [ignoreCase])

Checks if a string ends with a specific suffix.

Parameters:

  • ignoreCase (Optional): [Boolean Literal] - true for a case-insensitive comparison. Defaults to false.

Returns: 1.0 (true) or 0.0 (false).

Example: $endsWith('data_log.CSV', '.csv', true) → 1.0

$findFirstOf(string, charSet)

Finds the position of the first character in a string that is also present in a given set of characters.

Parameters:

  • charSet: A string containing the set of characters to search for.

Returns: The zero-based index of the first matching character, or -1 if no match is found.

Example: $findFirstOf('hello world 123', '0123456789') → 12

$indexOf(string, substring, [startIndex])

Finds the starting position of the first occurrence of a substring.

Parameters:

  • startIndex (Optional): The zero-based index from which to start the search. Defaults to 0.

Returns: The zero-based index of the substring, or -1 if not found.

Example: $indexOf('a-b-c-d', '-', 2) → 3

$isAlNum(string)

Checks if all characters in a string are alphanumeric (either letters or digits).

Returns: 1.0 (true) or 0.0 (false).

Example: $isAlNum('Device101') → 1.0

$isAlpha(string)

Checks if all characters in a string are alphabetic.

Returns: 1.0 (true) or 0.0 (false).

Example: $isAlpha('Device101') → 0.

$isDigit(string)

Checks if all characters in a string are digits (0-9).

Returns: 1.0 (true) or 0.0 (false).

Example: $isDigit('12345') → 1.0

$isLower(string)

Checks if all alphabetic characters in a string are lowercase.

Returns: 1.0 (true) or 0.0 (false).

Example: $isLower('error-1') → 1.0

$isSpace(string)

Checks if all characters in a string are whitespace characters (space, tab, newline, etc.).

Returns: 1.0 (true) or 0.0 (false).

Example: $isSpace(' \t ') → 1.0

$isUpper(string)

Checks if all alphabetic characters in a string are uppercase.

Returns: 1.0 (true) or 0.0 (false).

Example: $isUpper('ALARM') → 1.0

$lastIndexOf(string, substring)

Finds the starting position of the last occurrence of a substring.

Returns: The zero-based index of the substring, or -1 if not found.

Example: $lastIndexOf('a-b-c-d', '-') → 5

$length(string)

Returns the number of characters in a string.

Returns: A number.

Example: $length('hello') → 5

$startsWith(string, prefix, [ignoreCase])

Checks if a string begins with a specific prefix.

Parameters:

  • ignoreCase (Optional): [Boolean Literal] - true for a case-insensitive comparison. Defaults to false.

Returns: 1.0 (true) or 0.0 (false).

Example: $startsWith('ERR: Fault', 'err:', true) → 1.0

Type Conversion

These functions are dedicated to converting data between different formats.

$cast(value, type)

Explicitly converts a value to a specified data type.

Parameters:

  • type: [String Literal] - Supported: 'boolean', 'sint8', 'uint8', 'sint16', 'uint16', 'sint32', 'uint32', 'sint64', 'uint64', 'float32', 'float64', 'string'.

Returns: The converted value.

Example: $cast('123.789', 'sint32') → 123 (numeric).

$fromHex(hexString)

Converts a hexadecimal string to its decimal numeric value.

Returns: A number.

Example: $fromHex('FF') → 255.

$toHex(value, [prefix], [width])

Converts a numeric value into its hexadecimal string representation.

Parameters:

  • prefix (Optional true/false): Prefixes the output with "0x".

  • width (Optional number): The minimum number of characters for the output string.

Returns: A string.

Example: $toHex(4095, true, 4) → '0x0FFF'.

Hashing & Encoding

This category provides tools for data integrity checks and safe data transmission.

$base64decode(string)

Decodes a Base64 string back to its original form.

Returns: The decoded string.

Example: $base64decode('dXNlcjpwYXNz') → 'user:pass'

$base64encode(string)

Encodes a string into the Base64 format. Essential for transmitting data that may contain control characters or binary data within a text-based format like JSON.

Returns: A Base64 encoded string.

Example: $base64encode('user:pass') → 'dXNlcjpwYXNz'

$md5(string)

Calculates the MD5 hash of a string. Commonly used for checksums and non-critical integrity checks.

Returns: A 32-character hexadecimal string representing the hash.

Example: $md5('hello') → '5D41402ABC4B2A76B9719D911017C592'

$sha256(string)

Calculates the SHA-256 cryptographic hash of a string. Ideal for robust data integrity verification.

Returns: A 64-character hexadecimal string representing the hash.

Example: $sha256('hello') → '2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824'

$urlDecode(string)

Decodes a URL-encoded string (percent-encoding) back to its original form.

Returns: The decoded string.

Example: $urlDecode('a%3D1%26b%3D2') → 'a=1&b=2'

$urlEncode(string)

Encodes a string for safe transmission in a URL, replacing special characters with their percent-encoded equivalents.

Returns: An encoded string.

Example: $urlEncode('a=1&b=2') → 'a%3D1%26b%3D2'

Last updated