Skip to main content

Module symbol

Module symbol 

Source
Expand description

The symbol table: J’s s: names, held once each and referred to by a small integer.

A symbol is an atom whose value is a name. Two symbols made from the same text ARE the same atom — (s: <'a') = (s: <'a') is 1 however far apart the two sentences stand — so the text lives in one process-wide table and an array of symbols is an array of indices into it. The table is append-only: an index, once handed out, names the same text for the life of the process, which is what lets Data::Symbol hold plain u32s and copy, slice and index like any other flat buffer.

Index 0 is the empty name. It is the fill element, so overtaking an array of symbols needs no table lookup.

Symbols order by their TEXT, not by the order they were interned in, so every comparison resolves its operands here first.

Constants§

EMPTY
The empty name, which is also the fill element.

Functions§

cmp
Order two symbols by their names.
intern
The id of name, adding it to the table if it is new.
interned
How many distinct names the process has interned, the empty one included. It only ever grows.
name
The name id stands for. An id this process never handed out gives the empty name rather than panicking; no caller can produce one.
names
The names of many ids under one lock, which is what a comparison, a sort or a display of a whole array wants.

Type Aliases§

Id
A symbol’s index into the table. u32 is the width J’s own type code implies and leaves an array of symbols half the size of one of boxes.