Data Types

Rui supports several data types, from simple primitives to complex structures. The language uses implicit typing, so you don’t need to declare types explicitly.

Primitive Types

These are the basic building blocks of Rui:

Numbers

Rui supports both integers and floating-point numbers:

suppose age = 25
suppose price = 19.99
suppose negative = -10
suppose pi = 3.14159

write(age)
write(price)
write(negative)
write(pi)

Strings

Text data can be enclosed in single or double quotes:

suppose name = "Alice"
suppose message = 'Hello World'
suppose empty = ""

write(name)
write(message)
write("Empty string length: " + length(empty))

Booleans

Boolean values represent true or false:

suppose isStudent = true
suppose isWorking = false
suppose isAdult = age >= 18

write("Is student: " + isStudent)
write("Is working: " + isWorking)
write("Is adult: " + isAdult)

Null

The null value represents the absence of a value:

suppose data = null
suppose result = null

if (data == null) {
    write("No data available")
} else {
    write("Data: " + data)
}

Complex Types

These types can hold multiple values or structured data:

Arrays

Arrays are ordered collections of values:

suppose numbers = [1, 2, 3, 4, 5]
suppose fruits = ["apple", "banana", "orange"]
suppose mixed = [1, "hello", true, 3.14]
suppose empty = []

write("Numbers: " + numbers)
write("Fruits: " + fruits)
write("Mixed: " + mixed)
write("Empty array length: " + length(empty))

Objects

Objects store key-value pairs for structured data:

suppose person = {
    name: "Alice",
    age: 25,
    city: "New York",
    isStudent: true
}

write("Name: " + person.name)
write("Age: " + person.age)
write("City: " + person.city)
write("Is student: " + person.isStudent)

Functions

Functions are first-class citizens in Rui, meaning they can be assigned to variables:

define add(a, b) {
    return a + b
}

suppose operation = add
suppose result = operation(5, 3)
write("Result: " + result)

Type Checking

While Rui uses implicit typing, you can check types at runtime:

suppose value = 42


if (value is number) {
    write("Value is a number")
}

suppose text = "Hello"
if (text is string) {
    write("Text is a string")
}

Type Conversion

Rui automatically converts types when possible:

suppose num = 42
suppose str = "Hello"


write("Number: " + num)  


suppose numStr = "123"
suppose converted = parseInt(numStr)
write("Converted: " + converted)  

Best Practices

  • Use descriptive variable names: Choose names that clearly indicate the data type and purpose
  • Initialize variables: Always give variables an initial value
  • Use appropriate data structures: Choose arrays for lists, objects for structured data
  • Handle null values: Always check for null before using values
  • Be consistent: Use the same quote style throughout your code

Next Steps

Now that you understand data types, learn about Variables to store and manipulate this data.