std.core
What the language itself needs: aborting with a reason, the ready-made Throwable, and the
interfaces the built-in types satisfy.
panic and coroutineEnded are bound by the compiler, so nothing has to import this module to
reach them.
panic function
pub fn panic(message: string): void
Ends the program with message and a backtrace.
Not catchable. Its return type is never, so the flow analysis treats everything after a call as
unreachable — which is why expect can return a non-optional after panicking.
stdlib/std/core.lyr:22
coroutineEnded function
pub fn coroutineEnded(): void
Panics because a coroutine was resumed after its body had run to the end.
Called from a dispatcher nobody wrote, which is why nobody could have written the import either.
stdlib/std/core.lyr:29
assert function
pub fn assert(condition: bool, message: string): void
Panics with message when condition is false, for invariants the compiler does not check.
void rather than never: it does not replace a return, and a function ending in assert is
still LYR-SEM0017.
stdlib/std/core.lyr:43
todo function
pub fn todo(message: string): void
Marks a place that is still missing. Unlike a comment it reports itself when reached, with
not implemented: before the message.
stdlib/std/core.lyr:51
unreachable function
pub fn unreachable(message: string): void
Marks a branch that must never be taken, with unreachable: before the message.
todo means still to come; this means must never happen. Reaching it says that an assumption
stated somewhere else is wrong.
stdlib/std/core.lyr:59
Exception class
pub class Exception :: [Throwable]
The ready-made Throwable for throwing a message: throw Exception { text = "…" };.
text: string
pub fn message(): string
The text this exception was built with.
stdlib/std/core.lyr:71
Display interface
pub interface Display
What can be rendered as text — the anchor for write, writeln and std.fmt.
Every built-in scalar satisfies it through an extend, and a user type through ::. A value
held THROUGH the interface (let d: Display = 5;) stays rejected: an interface value is a fat
pointer and needs a reference, which a scalar has none of.
fn show(): string
This value as text.
stdlib/std/core.lyr:93
Equatable interface
pub interface Equatable<T>
Values of this type can be compared for equality.
Generic rather than fn equals(other: Equatable), so both sides carry the concrete type: an
interface as a parameter type would need an interface VALUE, and a scalar cannot be one — there
would be no Map<int, V>.
fn equals(other: T): bool
Whether the two are equal.
stdlib/std/core.lyr:136
Hashable interface
pub interface Hashable<T>
Values of this type can be hashed, which is what a Map key and a Set element need.
Equal values must produce equal hashes. No compiler checks it and every hash table depends on it. The reverse does not hold — two different values may collide.
It does not imply Equatable; there is no interface inheritance. A caller needing both requires
both: K :: [Hashable<K>, Equatable<K>].
fn hash(): int
The hash of this value.
stdlib/std/core.lyr:148
Ordered interface
pub interface Ordered<T>
Values of this type have an order — what sorting and range queries need.
One comparison instead of four methods: <, <=, > and >= all derive from it.
fn compare(other: T): int
Negative when this comes first, zero when the two are equal, positive when other comes
first — as strcmp.
stdlib/std/core.lyr:156
Add interface
pub interface Add<T>
Values of this type can be added: a + b is a.add(b).
fn add(other: T): T
The sum of this value and other.
stdlib/std/core.lyr:290
Sub interface
pub interface Sub<T>
Values of this type can be subtracted: a - b is a.sub(b).
fn sub(other: T): T
This value minus other.
stdlib/std/core.lyr:296
Mul interface
pub interface Mul<T>
Values of this type can be multiplied: a * b is a.mul(b).
fn mul(other: T): T
The product of this value and other.
stdlib/std/core.lyr:302
Div interface
pub interface Div<T>
Values of this type can be divided: a / b is a.div(b).
fn div(other: T): T
This value divided by other. What a division by zero does is the type's own business;
the built-in numerics panic.
stdlib/std/core.lyr:308
Into interface
pub interface Into<T>
A value of this type converts to T: x as T is x.into().
ONE target per type: the method is named into, and a type has one member of a name — a second
conversion is an ordinary named method. Total conversions only; a conversion that can fail
belongs in a named function returning an optional.
The numeric casts keep their opcodes: 1 as float never goes through here.
fn into(): T
This value as a T.
stdlib/std/core.lyr:379
OnModule interface
pub interface OnModule
A struct declaring this may stand as @Name before the module header.
stdlib/std/core.lyr:389
OnType interface
pub interface OnType
A struct declaring this may stand as @Name before a struct, class or enum declaration.
stdlib/std/core.lyr:392
OnFunction interface
pub interface OnFunction
A struct declaring this may stand as @Name before a top-level function.
stdlib/std/core.lyr:395