Lists and Dictionaries¶
Lists¶
:list(item1, item2, ...)
¶
Creates a list with the specified items.
@fruits = :list(apple, banana, orange)
@first = @fruits[0] # Result: apple
You can also create lists using brackets:
@fruits = [apple, banana, orange]
:split(text, delimiter)
¶
Splits a string into a list using the specified delimiter.
@text = apple,banana,orange
@fruits = :split(@text, ",")
@first = @fruits[0] # Result: apple
Dictionaries¶
:options(key1=value1, key2=value2, ...)
¶
Creates a dictionary with the specified key-value pairs.
@user = :options(name=John, age=30, city=São Paulo)
@name = @user[name] # Result: John
You can also create dictionaries using curly braces:
@user = {"name": "John", "age": "30", "city": "São Paulo"}
Accessing Elements¶
Accessing Lists¶
@list = :list(a, b, c)
@first = @list[0] # Result: "a"
@last = @list[2] # Result: "c"
Accessing Dictionaries¶
@dict = :options(name=John, age=30)
@name = @dict["name"] # Result: "John"
@age = @dict[age] # Result: "30" (using variable as key)