1c: Molds and Mold-Builders

$bite

Atom 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

Blocksize.

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 22a2^{2^a}, where aa or .a is the block size. That's because a block of size aa contains 2a2^a bits, and a binary number that is bb or .b bits wide can represent 2b2^b values.

A +bloq of 0 has a bitwidth of 1. (202^0 bits; can represent 220=22^{2^0}=2 different values.)

A +bloq of 1 has a bitwidth of 2. (212^1 bits; can represent 221=42^{2^1}=4 different values.)

A +bloq of 2 has a bitwidth of 4. (222^2 bits; can represent 222=162^{2^2}=16 different values.)

A +bloq of 3 has a bitwidth of 8. (232^3 bits; can represent 223=2562^{2^3}=256 different values.) And so on.

See the bit arithmetic section for operations that use +bloqs.


+each

Mold of fork between two types.

A mold generator. Produces a discriminated fork between two types, defaulting to $this.

Source

Examples


$gate

Function.

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.

See also: +lift, +cork


+list

List.

A mold generator. Generates a mold of a null-terminated list of a homogenous type.

Source

Examples

Discussion

See also: +turn, +snag


+lone

Face on mold.

A mold generator. Puts face of .p on the passed-in mold.

Source

Examples


+pair

Mold of pair of types.

A mold generator. Produces a tuple of two of the types passed in.

Source

Examples


+pole

Faceless +list.

A mold generator. A +list without the faces i and t.

Source

Examples


+qual

Mold of 4-type tuple.

A mold generator. Produces a tuple of four of the types passed in.

Source

Examples


+quip

Mold 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

Atom size or offset, in +bloqs.

Source

Examples


+trap

Core with one arm $.

A trap is a core with one arm $.

Source

Examples


+tree

Tree 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

Mold of three types.

A mold generator. A mold of the tuple of the three types passed in.

Source

Examples


+unit

Maybe.

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