2title = "1c: Molds and Mold-Builders"
11Either a single atom representing block size, or a cell containing a block size
12and an atom representing the number of blocks, called `step`. If `step` is not
13supplied, it defaults to a value of 1.
18 +$ bite $@(bloq [=bloq =step])
24 :: ++end gets the least significant bits of an atom.
49[`Atom`](/docs/glossary/atom) representing block size. A block of size `a` has a bitwidth of `2^a`.
60 :: ++met measures how many a-bloqs long an atom is.
80 > (met 5 9.999.999.999)
89You can think of `bloq` as a numeral system that can represent values of
90`a^2^2`, where `a` is the block size. That's because a block of size
91`a` contains `a^2` bits, and a binary number that is `b` bits wide can represent
94A `bloq` of 0 has a bitwidth of 1. (2^0 bits; can represent 2 values.)
96A `bloq` of 1 has a bitwidth of 2. (2^1 bits; can represent 4 values.)
98A `bloq` of 2 has a bitwidth of 4. (2^2 bits; can represent 16 values.)
100A `bloq` of 3 has a bitwidth of 8. (2^3 bits; can represent 256 values.)
104See the [bit arithmetic](/docs/hoon/reference/stdlib/2c) section for operations that use `bloq`s.
110Mold of fork between two types
112A mold generator. Produces a discriminated fork between two types, defaulting to
129 ?([%.y p=@t] [%.n p=@da])
135 ?([%.y p=*] [%.n p=""])
145A [`core`](/docs/glossary/core) with one arm, `$`--the empty name--which transforms a sample noun into a
146product noun. If used dryly as a type, the subject must have a sample type of
160 <1.ddq [* <46.hgz 1.pnw %140>]>
161<1.ddq [* <46.hgz 1.pnw %140>]>
165> (`gate`|=(a=* [a 'b']) 1)
170> (`gate`|=(a=@ [a 'b']) 1)
175dojo: hoon expression failed
180A `gate` is analogous to a function in other programming languages. We created
181this new jargon because other constructs in Urbit are "functions" in the
182mathematical sense. Any `gate` normalizes to an iron `gate`.
184See also: [`++lift`](/docs/hoon/reference/stdlib/2a#lift), [`++cork`](/docs/hoon/reference/stdlib/2n#cork)
192A mold generator. Generates a mold of a null-terminated list of a
200 $@(~ [i=item t=(list item)])
221> `(list @)`[1 2 'j' ~]
227See also: [`++turn`](/docs/hoon/reference/stdlib/2b#turn), [`++snag`](/docs/hoon/reference/stdlib/2b#snag)
235A mold generator. Puts face of `p` on the passed-in mold.
277A mold generator. Produces a tuple of two of the types passed in.
303Faceless [`list`](/docs/hoon/reference/stdlib/1c#list)
305A mold generator. A [`list`](/docs/hoon/reference/stdlib/1c#list) without the faces `i` and `t`.
312 $@(~ [item (pole item)])
318> =/(a "asdf" ?>(?=(^ a) `(lest @tD)`a))
319[i='a' t=[i='s' t=[i='d' t=[i='f' t=~]]]]
324['a' ['s' ['d' ['f' ~]]]]
333A mold generator. Produces a tuple of four of the types passed in.
339 |$ [first second third fourth]
340 [p=first q=second r=third s=fourth]
346> *(qual date time tape cord)
347[p=[[a=%.y y=0] m=0 t=[d=0 h=0 m=0 s=0 f=~]] q=~2000.1.1 r="" s='']
351> *(qual (list @) @u @ud @ux)
359Mold of pair of [`list`](/docs/hoon/reference/stdlib/1c#list) and type
361A mold generator. Produces a tuple of a [`list`](/docs/hoon/reference/stdlib/1c#list) of `item` and the mold of `state`.
379> `(quip @ @ux)`[[1 2 3 4 ~] 0x10]
385A common pattern in Hoon code is to return a `list` of changes, along with a
386new state. You'll often see `quip` used in Gall apps.
392Atom size or offset, in [bloq](#bloq)s.
417[`Core`](/docs/glossary/core) with one arm `$`
419A trap is a [`core`](/docs/glossary/core) with one arm `$`.
433<1?ruo 1.mhl [product=<1|xpg [* * *]> <46.hgz 1.pnw %140>]>
452A mold generator. A `tree` can be empty, or contain a node of a type and
453left/right sub `tree` of the same type. Pretty-printed with `{}`.
460 $@(~ [n=node l=(tree node) r=(tree node)])
466> `(tree [@ tape])`[[1 "hi"] [[2 "bye"] ~ ~] ~]
476A mold generator. A mold of the tuple of the three types passed in.
482 |$ [first second third]
483 [p=first q=second r=third]
494> *(trel cord bloq tape)
504A mold generator. A `unit` is either `~` or `[~ u=item]`, where `item` is the
505type that was passed in.
534Using a `unit` allows you to specify something that may not be there.
536See also: [`++bind`](/docs/hoon/reference/stdlib/2a#bind)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list