Collections (List & Map)
Wysna provides high-performance, built-in collection primitives: list[T] (dynamic arrays) and dict[K, V] (hash maps). Both obey pure value semantics via Automatic Reference Counting (ARC) and Copy-on-Write (CoW).
Lists (list[T])
Section titled “Lists (list[T])”A list is a contiguous, dynamically-sized array of elements of uniform type.
Creating and Modifying Lists
Section titled “Creating and Modifying Lists”fn main() -> unit { # Initializing a list of integers let mut numbers = [10, 20, 30]
# Appending elements numbers.append(40) numbers.append(50)
# Length print("Count:", len(numbers)) # 5
# Indexing print("First:", numbers[0]) # 10 print("Last: ", numbers[len(numbers) - 1]) # 50
# Updating an element numbers[1] = 99 print("Updated:", numbers) # [10, 99, 30, 40, 50]}Common List Methods
Section titled “Common List Methods”list.append(item): Appends an element to the end of the list.list.pop() -> T?: Removes and returns the last element, ornoneif empty.len(list): Returns the current number of elements.
Dictionaries (dict[K, V])
Section titled “Dictionaries (dict[K, V])”A dict is an associative hash map storing key-value pairs. Keys must belong to predictable types (int, str, bool, or enum); floating-point keys are prohibited compile-time (W2010).
Initializing and Accessing Dictionaries
Section titled “Initializing and Accessing Dictionaries”fn main() -> unit { let mut scores: dict[str, int] = { "alice": 95, "bob": 88, }
# Inserting or updating a key scores["charlie"] = 92 scores["alice"] = 100
# Safe retrieval with fallback via .get() let bob_score = scores.get("bob") ?? 0 print("Bob score:", bob_score)
# Checking key existence via .get() if scores.get("david") != none { print("David is present") } else { print("David not found") }}Value Semantics with Dictionaries
Section titled “Value Semantics with Dictionaries”Assigning a dictionary creates a shared view until modified via Copy-on-Write:
fn main() -> unit { let base = {"mode": "dark", "fontSize": "14"} let mut custom = base custom["fontSize"] = "16"
print("Base: ", base["fontSize"]) # 14 print("Custom:", custom["fontSize"]) # 16}