Variables & Types

Storing and manipulating data in Ry.

Declaring Variables

In Ry, variables are declared using the data keyword. Ry is dynamically typed, meaning you don't need to specify the data type explicitly; the interpreter infers it from the value assigned.

data message = "Hello Ry!"
data count = 42
data pi = 3.14159

Data Types

Ry supports several fundamental data types out of the box:

Strings & Interpolation

Strings in Ry are powerful. You can embed variables directly into strings using the ${} syntax. This is often cleaner than concatenating strings manually.

data name = "Alice"
data age = 25

# String interpolation
out("User: ${name}, Age: ${age}")

Characters

A Char represents a single character. Unlike strings, characters are enclosed in single quotes '.

data letter = 'A'
data symbol = '$'

Numbers

Numbers handle arithmetic operations. Whether you are working with whole numbers or decimals, the Number type covers it.

data x = 10
data y = 5.5
data result = x + y

out(result) # Output: 15.5

Lists (Arrays)

Ry supports lists, which are ordered collections of values. You can create a list by enclosing comma-separated values in square brackets [].

data numbers = [1, 2, 3, 5, 8]
data mixed = ["apple", 100, true]

# Access elements by index (starting from 0)
out(numbers[0]) # Output: 1

# You can also modify elements
mixed[1] = 200
out(mixed[1]) # Output: 200

Maps (Dictionaries)

Maps allow you to store data in key-value pairs. You can create a map using curly braces {}.

data user = {
    "name": "Alice",
    "role": "Admin"
}

out(user["name"]) # Output: Alice

user["score"] = 100

For more complex logic, learn how to manipulate these values in the Operators section.

Next: Operators!