Standard library
Kata embeds its standard library when built. Core native operations live in Rust; many data structures and protocols are defined in KataScript. The library source is part of the same repository as the interpreter.
Modules
Section titled “Modules”| Module | Role |
|---|---|
core | Opt, Res, iteration, lifecycle, indexing, conversion, and hashing protocols |
dsa | Arr, ArrIter, Map, MapIter, and Slot |
mem | RawPtr operations, Ptr, Buf, Allocator, and allocation support |
The prelude exposes core names and the common collection types without an import. import dsa binds a module; import mem.{Ptr, Buf} binds selected names. The import system resolves built-in modules, not neighboring script files or downloaded packages.
import dsalet values = dsa.Arr[Int].new()values.push(42)print(values[0])Optional values
Section titled “Optional values”Opt[T] has two variants: Val(T) for presence and Non for absence. Construct them with an explicit type, as Opt[Int].Val(42) or Opt[Int].Non. Array and map get operations use this type.
| Operation | Contract |
|---|---|
option.unwrap() | Return the payload, or stop on absence |
option.unwrap_or(default) | Return the payload, or the supplied default |
option? | Return the payload, or return the absent enum value from the function |
option! | Return the payload, or stop on absence |
let absent = Opt[Int].Nonprint(absent.unwrap_or(0))match Opt[Int].Val(42) { Val(value) -> print(value), Non() -> print("absent"),}The default is an ordinary call argument, evaluated before unwrap_or is called. It is not a lazy fallback function.
Results
Section titled “Results”Res[T, E] has Val(T) for success and Err(E) for failure. Both are ordinary enum values. A failure can be inspected by the caller without terminating evaluation.
| Operation | Contract |
|---|---|
result.unwrap() | Return success payload, or stop on failure |
result.unwrap_or(default) | Return success payload, or the supplied default |
result.unwrap_err() | Return error payload, or stop on success |
result.is_val() | Whether the variant is Val |
result.is_err() | Whether the variant is Err |
result? | Unwrap success or immediately return the failure value |
result! | Unwrap success or stop on failure |
let result = Res[Int, Str].Err("missing value")print(result.is_err())print(result.unwrap_or(0))print(result.unwrap_err())Propagation preserves the complete enum value; it does not automatically convert error types. Val, Err, and Non are library variant names, not keywords. User enums may use the same names. See the result tutorial for an API that composes failures.
Protocols
Section titled “Protocols”| Interface | Required behavior |
|---|---|
Iter[T] | next(self): Opt[T] yields an item or signals completion |
ToIter[T] | to_iter(self): Iter[T] supplies an iterator |
GetItem[K, V] | get_item(self, key: K): V reads via brackets |
SetItem[K, V] | set_item(self, key: K, val: V) writes via brackets |
ToBin | to_bin(self): Bin converts to bytes |
Hash | hash(self): U64 supplies a hash value |
Drop | drop(self) handles scope-exit cleanup |
Copy | copy(self): Self declares copy behavior |
Dupe | dupe(self): Self declares duplication behavior |
Declaring conformance uses impl Kind as Interface { ... }. Generic validation and lifecycle dispatch remain incomplete. Drop, Copy, and Dupe are available protocol definitions, not a completed ownership or deep-copy guarantee. See language status.
Memory
Section titled “Memory”RawPtr is an opaque primitive pointer. Ptr[T] layers typed access over it, Buf[T] adds a capacity, and Arr[T] adds a live length and collection operations. Allocator describes allocation behavior; the mem module supplies the lower-level operations.
Raw intrinsics require an unsafe block. The browser playground is intended for short language experiments and has a limited execution budget; it is not a memory debugger. Prefer Arr and Map in application examples, and consult the library source before changing memory code.