1c: Molds and Mold-Builders
$bite
$biteAtom slice specifier.
Either a single $atom representing block size, or a cell containing a block size and an $atom representing the number of blocks, called +step. If +step is not supplied, it defaults to a value of 1.
Source
+$ bite $@(bloq [=bloq =step])Examples
+end gets the least significant bits of an atom.
> (end [1 1] 255)
3> (end 1 255)
3> (end 3 255)
255> (end 3 65.535)
255> (end [3 2] 65.535)
65.535+bloq
+bloqBlocksize.
Atom representing block size. A block of size a has a bitwidth of 2^a.
Source
Examples
Discussion
You can think of +bloq as a numeral system that can represent values of , where or .a is the block size. That's because a block of size contains bits, and a binary number that is or .b bits wide can represent values.
A +bloq of 0 has a bitwidth of 1. ( bits; can represent different values.)
A +bloq of 1 has a bitwidth of 2. ( bits; can represent different values.)
A +bloq of 2 has a bitwidth of 4. ( bits; can represent different values.)
A +bloq of 3 has a bitwidth of 8. ( bits; can represent different values.) And so on.
See the bit arithmetic section for operations that use +bloqs.
+each
+eachMold of fork between two types.
A mold generator. Produces a discriminated fork between two types, defaulting to $this.
Source
Examples
$gate
$gateFunction.
A core with one arm, $ (the empty name) which transforms a sample $noun into a product $noun. If used dryly as a type, the subject must have a sample type of *.
Source
Examples
Discussion
A $gate is analogous to a function in other programming languages. We created this new jargon because other constructs in Urbit are "functions" in the mathematical sense. Any $gate normalizes to an iron $gate.
+list
+listList.
A mold generator. Generates a mold of a null-terminated list of a homogenous type.
Source
Examples
Discussion
+lone
+loneFace on mold.
A mold generator. Puts face of .p on the passed-in mold.
Source
Examples
+pair
+pairMold of pair of types.
A mold generator. Produces a tuple of two of the types passed in.
Source
Examples
+pole
+poleFaceless +list.
A mold generator. A +list without the faces i and t.
Source
Examples
+qual
+qualMold of 4-type tuple.
A mold generator. Produces a tuple of four of the types passed in.
Source
Examples
+quip
+quipMold of pair of +list and type.
A mold generator. Produces a tuple of a +list of $item and the mold of $state.
Source
Examples
Discussion
A common pattern in Hoon code is to return a +list of changes, along with a new state. You'll often see +quip used in Gall apps.
+step
+stepAtom size or offset, in +bloqs.
Source
Examples
+trap
+trapCore with one arm $.
A trap is a core with one arm $.
Source
Examples
+tree
+treeTree mold generator.
A mold generator. A +tree can be empty, or contain a node of a type and left/right sub +tree of the same type. Pretty-printed with {}.
Source
Examples
+trel
+trelMold of three types.
A mold generator. A mold of the tuple of the three types passed in.
Source
Examples
+unit
+unitMaybe.
A mold generator. A +unit is either ~ or [~ u=item], where $item is the type that was passed in.
Source
Examples
Discussion
Using a +unit allows you to specify something that may not be there.
See also: +bind
Last updated