Built-in Functions
Rui comes with a comprehensive set of built-in functions that make common programming tasks easy and efficient. These functions are always available without needing to import anything.
Output Functions
The write() function is the primary way to display output in Rui:
write("Hello, World!")
write("Multiple", "arguments", "supported")
write("Name: " + name)
write("Age: " + age)Type Checking
Use the type() function to check the type of any value:
suppose str = "Hello"
suppose num = 42
suppose arr = [1, 2, 3]
suppose obj = {name: "Alice"}
write("String type: " + type(str)) // string
write("Number type: " + type(num)) // number
write("Array type: " + type(arr)) // array
write("Object type: " + type(obj)) // objectString Functions
Rui provides several built-in string manipulation functions:
suppose text = "Hello World"
write("Original: " + text)
write("Upper: " + text.upper()) // HELLO WORLD
write("Lower: " + text.lower()) // hello world
write("Split: " + text.split(" ")) // ["Hello", "World"]Array Functions
Arrays come with built-in methods for manipulation:
suppose arr = [1, 2, 3]
// Add elements
arr.push(4)
write("After push: " + arr) // [1, 2, 3, 4]
// Remove last element
write("Pop result: " + arr.pop()) // 4
write("After pop: " + arr) // [1, 2, 3]
// Add to beginning
arr.unshift(0)
write("After unshift: " + arr) // [0, 1, 2, 3]
// Remove from beginning
write("Shift result: " + arr.shift()) // 0
write("After shift: " + arr) // [1, 2, 3]Utility Functions
Rui provides utility functions for common operations:
suppose str = "123"
suppose arr = ["a", "b", "c"]
write("Parse int: " + parseInt(str)) // 123
write("Parse float: " + parseFloat("3.14")) // 3.14
write("Join array: " + join(arr, "-")) // a-b-c
write("Length: " + length(arr)) // 3Array Indexing and Slicing
Access and manipulate array elements with indexing and slicing:
suppose arr = [10, 20, 30, 40, 50]
write("First element: " + arr[0]) // 10
write("Last element: " + arr[-1]) // 50
write("Middle element: " + arr[2]) // 30
// Slicing
write("Slice [1:4]: " + arr[1:4]) // [20, 30, 40]
write("Slice [:3]: " + arr[:3]) // [10, 20, 30]
write("Slice [2:]: " + arr[2:]) // [30, 40, 50]Object Property Access
Access object properties using dot notation:
suppose person = {
name: "Alice",
age: 25,
city: "New York"
}
write("Person: " + person)
write("Name: " + person.name)
write("Age: " + person.age)
write("City: " + person.city)Best Practices
- Use the right function: Choose the most appropriate built-in function for your task
- Handle errors gracefully: Check for valid input before using parse functions
- Combine functions effectively: Chain operations for complex transformations
- Use write() for debugging: Print intermediate values to understand your data flow
- Leverage length() for validation: Check array/string sizes before processing
Next Steps
Now that you understand built-in functions, learn about Operators to perform calculations and comparisons.