Skip to content

Functions

Pranav Verma edited this page Dec 3, 2024 · 6 revisions

This page documents key built-in functions and user-defined function in Tidal.

Built In Functions

print()

print("Hello World"); /* Outputs: Hello World */
print(42);           /* Outputs: 42 */
print([1,2,3]);     /* Outputs: [1, 2, 3] */

input()

var x = int(input("Please Enter Value: "));

type()

var num = 42;
print(type(num));    /* Outputs: int */

var text = "hello";
print(type(text));   /* Outputs: str */

eval()

Works on: String containing valid Tidal code
Returns: Result of evaluating the code
Notes:

  • Code runs in the current scope - can access existing variables
  • Can evaluate expressions and statements
  • Variables created inside eval() are not accessible outside
  • Returns the last evaluated expression's value
  • Throws an error if code is invalid
var result = eval("5 + 3");
print(result);    /* Outputs: 8 */

len()

var string = 42;
print(len(string));

del()

var x = 42;
print(x);

del(x);

var x = 10;
print(x);

upper()

Works on: Strings only
Returns: New uppercase string

var text = "hello";
var upper = upper(text);

lower()

Works on: Strings only
Returns: New lowercase string

var text = "HELLO";
var lower = lower(text);

strip()

Works on: Strings only
Returns: New string with whitespace removed from both ends

var text = "  hello  ";
var clean = strip(text);

copy()

Works on: Arrays only
Returns: New copy of array

novar original = [1, 2, 3];
var copied = copy(original);
/* In this example, you will be able to make modifications
   to the copied array but not to the original. */

extend()

Works on: Arrays only
Returns: New combined array

var arr1 = [1, 2];
var arr2 = [3, 4];
var combined = extend(arr1, arr2); 

insert()

Works on: Arrays only
Returns: null (modifies original array)

var arr = [1, 2, 3];
insert(arr, 0); /* Adds to end: [1, 2, 3, 0] */
insert(arr, 4, 1); /* Inserts at index: [1, 4, 2, 3, 0] */

sort()

Works on: Arrays only
Returns: null (modifies original array)

var arr = [3, 1, 2];
sort(arr);

reverse()

var arr = [1, 2, 3];
reverse(arr); 

clear()

Works on: Arrays only
Returns: null (modifies original array)

var arr = [1, 2, 3];
clear(arr);  

count()

Works on: Both Strings and Arrays
Returns: Number of occurrences

var arr = [1, 2, 2, 3];
print(count(arr, 2));     /* Returns: 2 */

var text = "hello hello";
print(count(text, "hello")); /* Returns: 2 */

User Functions

Function Definition

func greet(name) {
    print("Hello " + name);
}

return Statement

func add(x, y) {
    return x + y;
}

var sum = add(5, 3);
print(type(sum));

Clone this wiki locally