Data Types
Risor has a small, practical set of data types covering primitives, containers, and a few specialized types.
Primitives
Bool
Boolean values are true and false:
let active = true
let done = falseInt
Integers are 64-bit signed values:
let x = 42
let negative = -7Integer literals can be written in decimal, hexadecimal, or binary:
0xFF // 255 (hexadecimal)
0b1010 // 10 (binary)Float
Floating-point numbers are 64-bit IEEE 754 values:
let pi = 3.14
let tiny = 0.001String
Strings are immutable sequences of characters, written with double quotes or backtick template strings:
let greeting = "hello"
let message = `Hello ${name}!`See the strings page for full details on string interpolation, indexing, and slicing.
Nil
nil represents the absence of a value:
let x = nilContainers
List
Lists are ordered, mutable collections of values. They can hold mixed types:
let items = [1, 2, 3]
let mixed = [1, "two", true, nil]Lists support indexing, slicing, and negative indexing. See the collections page for details.
Map
Maps are unordered collections of key-value pairs with string keys:
let person = {name: "Alice", age: 30}Values are accessed with dot notation or bracket notation:
person.name // "Alice"
person["age"] // 30Other Types
Byte
A byte represents a single byte value in the range 0-255:
let b = byte(65) // ASCII 'A'Bytes
A bytes value is a mutable sequence of bytes:
let data = bytes("hello")Range
range creates a lazy sequence of integers:
let r = range(10) // 0 through 9
list(range(5)) // [0, 1, 2, 3, 4]Ranges are lazy. They produce values on demand rather than allocating a full list in memory.
Error
Error values represent failures and can be created with the error function:
let err = error("file %s not found", filename)See the error handling page for full details.
Truthiness
Values in Risor follow these truthiness rules:
| Value | Truthy? |
|---|---|
true | yes |
false | no |
0 (int) | no |
| non-zero int | yes |
0.0 (float) | no |
| non-zero float | yes |
"" (empty string) | no |
| non-empty string | yes |
nil | no |
empty list [] | no |
| non-empty list | yes |
empty map {} | no |
| non-empty map | yes |
| error | yes |
| function | yes |
These rules apply wherever a boolean is expected, such as in if conditions
and logical operators.