2title = "1c: Molds and Mold-Builders"
11Atom representing block size. A block of size `a` has a bitwidth of `2^a`.
22 :: ++met measures how many a-bloqs long an atom is.
42 > (met 5 9.999.999.999)
51You can think of `bloq` as a numeral system that can represent values of
52`a^2^2`, where `a` is the block size. That's because a block of size
53`a` contains `a^2` bits, and a binary number that is `b` bits wide can represent
56A `bloq` of 0 has a bitwidth of 1. (2^0 bits; can represent 2 values.)
58A `bloq` of 1 has a bitwidth of 2. (2^1 bits; can represent 4 values.)
60A `bloq` of 2 has a bitwidth of 4. (2^2 bits; can represent 16 values.)
62A `bloq` of 3 has a bitwidth of 8. (2^3 bits; can represent 256 values.)
66See the [bit arithmetic](@/docs/hoon/reference/stdlib/2c.md) section for operations that use `bloq`s.
72Mold of fork between two types
74A mold generator. Produces a discriminated fork between two types, defaulting to
80 |*([a=mold b=mold] $%([$| p=b] [$& p=a]))
87 ?({$.y p/@t} {$.n p/@da})
91 ?({$.y p/*} {$.n p/""})
100A core with one arm, `$`--the empty name--which transforms a sample noun into a
101product noun. If used dryly as a type, the subject must have a sample type of
116 <1.rdl {* <31.ohr 1.jmk $143>}>
117 <1.rdl {* <31.ohr 1.jmk $143>}>
119 > (`gate`|=(a=* [a 'b']) 1)
122 > (`gate`|=(a=@ [a 'b']) 1)
129A `gate` is analogous to a function in other programming languages. We created
130this new jargon because other constructs in Urbit are "functions" in the
131mathematical sense. Any `gate` normalizes to an iron `gate`.
133See also: [`++lift`](../2a), [`++cork`](../2n)
140A mold generator. Generates a mold of a null-terminated list of a
148 |*(a=mold $@($~ (lest a)))
163 > `(list @)`[1 2 'j' ~]
169See also: [`++turn`](../2b), [`++snag`](../2b)
176A mold generator. Puts face of `p` on the passed-in mold.
208A mold generator. Produces a tuple of two of the types passed in.
215 |*([a=mold b=mold] [p=a q=b])
234A mold generator. A `list` without the faces `i` and `t`.
240 |*(a=mold $@($~ [a (pole a)]))
247 > =/(a "asdf" ?>(?=(^ a) `(lest @tD)`a))
248 [i='a' t=[i='s' t=[i='d' t=[i='f' t=~]]]]
250 > `(pole char)`"asdf"
251 ['a' ['s' ['d' ['f' ~]]]]
260A mold generator. Produces a tuple of four of the types passed in.
266 |* [a=mold b=mold c=mold d=mold]
273 > *(qual date time tape cord)
274 [p=[[a=%.y y=0] m=0 t=[d=0 h=0 m=0 s=0 f=~]] q=~292277024401-.1.1 r="" s='']
276 > *(qual (list @) @u @ud @ux)
283Mold of pair of `list` and type
285A mold generator. Produces a tuple of a `list` of `a` and the mold of `b`.
291 |*([a=mold b=mold] [(list a) b])
300 > `(quip @ @ux)`[[1 2 3 4 ~] 0x10]
306A common pattern in Hoon code is to return a `list` of changes, along with a
307new state. You'll often see `quip` used in Gall apps.
314A trap is a core with one arm `$`.
327 <1?dxy 1.oeg {a/<1|rbb {* <31.ohr 1.jmk $143>}> <31.ohr 1.jmk $143>}>
342A mold generator. A `tree` can be empty, or contain a node of a type and
343left/right sub `tree` of the same type. Pretty-printed with `{}`.
349 |*(a=mold $@($~ [n=a l=(tree a) r=(tree a)]))
355 > `(tree [@ tape])`[[1 "hi"] [[2 "bye"] ~ ~] ~]
365A mold generator. A mold of the tuple of the three types passed in.
371 |*([a=mold b=mold c=mold] [p=a q=b r=c])
380 > *(trel cord bloq tape)
389A mold generator. A `unit` is either `~` or `[~ u=a]`, where `a` is the
390type that was passed in.
397 |*(a=mold $@($~ [$~ u=a]))
417Using a `unit` allows you to specify something that may not be there.
419See also: [`++bind`](../2b)
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