This document describes the built-in reference types in Ovum, their methods, and the standard interfaces that all types implement.
String is a reference type (not primitive) for text data. All strings are immutable by default and implement
IStringConvertible, IComparable, and IHashable.
Length(): int - Returns the number of characters in the stringToString(): String - Returns the string itself (implements IStringConvertible)IsLess(other: Object): bool - Lexicographic comparison (implements IComparable)GetHash(): int - Returns hash code for the string (implements IHashable)+ operator - String concatenation (e.g., "Hello" + " " + "World")val greeting: String = "Hello, World!"
val length: Int = greeting.Length() // Returns 13
val combined: String = "Hello" + ", " + "World!"
// String comparison
val a: String = "apple"
val b: String = "banana"
val isLess: bool = a.IsLess(b) // true (lexicographic order)
// String hashing
val hash: int = greeting.GetHash()
Note: For detailed information about nullable types, see
nullable.md. This section only covers basic information.
Any primitive type can be made nullable by appending ? (e.g., Int?, String?). Nullable types are passed by
reference and can hold either a value or null.
Important: You cannot directly call methods on nullable types using . - you must use the safe call operator ?..
val nullableString: String? = "Hello"
// val length: Int = nullableString.Length() // ERROR: Cannot call method directly on nullable
val safeLength: Int = nullableString?.Length() ?: 0 // Correct: Use safe call
Ovum provides specialized array classes for different data types. Arrays are reference types and support indexing,
iteration, and length operations. All arrays have dynamic length. All array types implement IComparable and
IHashable.
IntArray - Array of 64-bit signed integersFloatArray - Array of 64-bit floating-point numbersBoolArray - Array of Boolean valuesCharArray - Array of charactersByteArray - Array of 8-bit unsigned integersPointerArray - Array of raw memory addresses (unsafe)ObjectArray - Array of any object type (implements Object)StringArray - Convenience array of String objects (used for Main function)File is a reference type for file operations.
Read(size: int): ByteArray - Reads given amount bytes from the fileReadLine(): String - Reads all text from the file as UTF-8, returns null on errorWrite(data: ByteArray): int - Writes all bytes to the file, returns number of bytes writtenWriteLine(text: String): Void - Writes a string to file with '\n'Open(path: String, mode: String): Void - Opens the file at the given path with the specified modeClose(): Void - Closes the file handleIsOpen(): bool - Returns true if the file is currently openEof(): bool - Returns true if the end of the file has been reachedSeek(position: int): void - Sets the file positionTell(): int - Returns the current file positionAll array types support the following methods:
Length(): int - Returns the number of elements in the array[index]: ElementType - Indexing operator for element access[index] = value - Assignment operator for mutable arraysToString(): String - String representation of the array (implements IStringConvertible)IsLess(other: Object): bool - Lexicographic comparison of array elements (implements IComparable)Equals(other: Object): bool - Equality comparison of array contents (implements IComparable)GetHash(): Int - Hash code based on array contents (implements IHashable)Reserve(newCapacity: int): Void - Reserves capacity for the arrayShrinkToFit(): Void - Shrinks the array capacity to fit its sizeClear(): Void - Clears all elements from the arrayAdd(value: ElementType): Void - Appends an element to the end of the arrayInsertAt(index: int, value: ElementType): Void - Inserts an element at the specified indexRemoveAt(index: int): Void - Removes the element at the specified indexAll of them can be created with a specified length:
var intArr: IntArray = IntArray(10, 0) // Array of 10 integers
var floatArr: FloatArray = FloatArray(5, 0.0) // Array of 5 floats
// Creating and using arrays
val numbers: IntArray = IntArray(3)
numbers[0] = 10
numbers[1] = 20
numbers[2] = 30
val count: Int = numbers.Length() // Returns 3
// Iteration
for (num in numbers) {
sys::Print(Int(num).ToString())
}
// Array comparison
val arr1: IntArray = IntArray(2)
arr1[0] = 1
arr1[1] = 2
val arr2: IntArray = IntArray(2)
arr2[0] = 1
arr2[1] = 3
val isLess: Bool = arr1.IsLess(arr2) // true (lexicographic comparison)
// Array hashing
val hash: Int = numbers.GetHash()
// String array (used in Main)
fun Main(args: StringArray): Int {
for (arg in args) {
sys::Print("Argument: " + arg)
}
return 0
}
All types in Ovum implicitly implement certain standard interfaces that provide common functionality.
The implicit root interface for all types. Provides:
destructor(): Void - Virtual destructor called by GC during finalizationProvides string conversion capability:
ToString(): String - Converts the object to its string representationAll built-in types implement this interface:
val num: Int = 42
val str: String = num.ToString() // "42"
val flag: Bool = true
val flagStr: String = flag.ToString() // "true"
Provides ordering capability for sorting and comparison:
IsLess(other: Object): bool - Returns true if this object is less than the otherEquals(other: Object): bool - Returns true if this object is equal to the otherRequired for user-defined types used as parameters to pure functions (ensures stable ordering).
val a: Int = 5
val b: Int = 10
val isLess: bool = a.IsLess(b) // true
val isEqual: bool = a.Equals(b) // false
Provides hashing capability for use in hash tables and caching:
GetHash(): int - Returns a hash code for the objectval text: String = "Hello"
val hash: Int = text.GetHash()
Object (implicit root)
├── IStringConvertible
├── IComparable
└── IHashable
Built-in Types:
├── String (implements all interfaces)
├── File (implements all interfaces)
├── IntArray, FloatArray, etc. (implements all interfaces)
├── Int, Float, Bool, Char, Byte (implements all interfaces)
└── Int?, String?, File?, etc. (nullable versions, implements all interfaces)