.nib std
nib 0.3.0

module always in scope

Handle

A unique identity minted at run time with Handle.make. It has no literal and no conversion from any other type, so it cannot be guessed or forged.

A Handle is a value whose only property is which call made it. Each call to Handle.make answers a new one, different from every other symbol in the process, and two symbols are == only when they are the same mint. There is no literal for a symbol and no way to turn a String or an Int into one, so the only way to hold a symbol is to have been given it.

That makes a symbol a good key for something that should not be reachable by name: a slot in an effector's state, or a network connection, which is how Net.Socket hands out connections.

let a = Handle.make("session");
let b = Handle.make("session");
(a == a, a == b)
(true, false)

A symbol prints as Handle(<description>)#<n>, where n is its position in the order symbols were made in this process. The print is for diagnostics only: nothing reads it back, and n depends on whatever else the program minted first. Symbols can be compared with == and used as Map keys or Set members, but they cannot be ordered with <, interpolated into a string, or rendered by Json.render.

let alice = Handle.make("alice");
let bob = Handle.make("bob");
let owners = Map.set(Map.set({}, alice, 3), bob, 5);
(Map.get_or(owners, bob, 0), Map.get_or(owners, Handle.make("bob"), 0))
(5, 0)

Functions

funcmake
func make :: String -> Handle

A new symbol, distinct from every symbol made before it. desc is a description that appears when the symbol is printed; it is not part of the identity, so two symbols made from the same description are still different. An empty description prints as just the number.

#[Handle.make("alpha"), Handle.make("alpha"), Handle.make("")]
#[Handle(alpha)#1, Handle(alpha)#2, Handle(3)]