-
Notifications
You must be signed in to change notification settings - Fork 2
Functions
Pranav Verma edited this page Dec 3, 2024
·
6 revisions
This page documents key built-in functions and user-defined function in Tidal.
print("Hello World"); /* Outputs: Hello World */
print(42); /* Outputs: 42 */
print([1,2,3]); /* Outputs: [1, 2, 3] */
var x = int(input("Please Enter Value: "));
var num = 42;
print(type(num)); /* Outputs: int */
var text = "hello";
print(type(text)); /* Outputs: str */
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 */
var string = 42;
print(len(string));
var x = 42;
print(x);
del(x);
var x = 10;
print(x);
Works on: Strings only
Returns: New uppercase string
var text = "hello";
var upper = upper(text);
Works on: Strings only
Returns: New lowercase string
var text = "HELLO";
var lower = lower(text);
Works on: Strings only
Returns: New string with whitespace removed from both ends
var text = " hello ";
var clean = strip(text);
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. */
Works on: Arrays only
Returns: New combined array
var arr1 = [1, 2];
var arr2 = [3, 4];
var combined = extend(arr1, arr2);
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] */
Works on: Arrays only
Returns: null (modifies original array)
var arr = [3, 1, 2];
sort(arr);
var arr = [1, 2, 3];
reverse(arr);
Works on: Arrays only
Returns: null (modifies original array)
var arr = [1, 2, 3];
clear(arr);
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 */
func greet(name) {
print("Hello " + name);
}
func add(x, y) {
return x + y;
}
var sum = add(5, 3);
print(type(sum));
Blue Lagoon.
A Pranav Verma Production.