on 4fdc19d help sign in
332 lines 8.5 kB history raw
1+++
2title = "Irregular forms"
3weight = 20
4template = "doc.html"
5aliases = ["docs/reference/hoon-expressions/irregular/"]
6+++
8## Quick Lookup of Irregular Forms
10| Form | Regular Form |
11| ---- | ------------ |
12| `_foo` | [`$_`](https://urbit.org/docs/hoon/reference/rune/buc#_-buccab), normalizes to an example |
13| `foo=bar` | [`$=`](https://urbit.org/docs/hoon/reference/rune/buc#_-buctis), wraps a face around a value |
14| `?(%foo %bar %baz)` | [`$?`](https://urbit.org/docs/hoon/reference/rune/buc#_-bucwut), forms a type union |
15| `(fun a b c)` | [`%:`](https://urbit.org/docs/hoon/reference/rune/cen#_-cencol), calls a gate with n arguments |
16| `~(arm core arg)` | [`%~`](https://urbit.org/docs/hoon/reference/rune/cen#_-censig), pulls an arm in a door |
17| `foo(x 1, y 2, z 3)` | [`%=`](https://urbit.org/docs/hoon/reference/rune/cen#_-centis), resolve a wing with changes |
18| `[a b c]` | [`:*`](https://urbit.org/docs/hoon/reference/rune/col#_-coltar) or [`$:`](https://urbit.org/docs/hoon/reference/rune/buc#_-buccol), constructs _n_-tuple in normal mode or its structure in structure mode |
19| `~[a b c]` | [`:~`](https://urbit.org/docs/hoon/reference/rune/col#_-colsig), constructs null-terminated list |
20| `+(42)` | [`.+`](https://urbit.org/docs/hoon/reference/rune/dot#_-dotlus), increments with Nock 4 |
21| `=(a b)` | [`.=`](https://urbit.org/docs/hoon/reference/rune/dot#_-dottis), tests for equality wiht Nock 5 |
22| ``foo`bar` | [`^-`](https://urbit.org/docs/hoon/reference/rune/ket#_-kethep), typecasts by explicit type label |
23| `foo=bar` | [`^=`](https://urbit.org/docs/hoon/reference/rune/ket#_-kettis), binds name to value |
24| `*foo` | [`^*`](https://urbit.org/docs/hoon/reference/rune/ket#_-kettar), bunts (produces default mold value) |
25| `,foo` | [`^:`](https://urbit.org/docs/hoon/reference/rune/ket#_-ketcol), produces “factory” gate for type |
26| `:(fun a b c d)` | [`;:`](https://urbit.org/docs/hoon/reference/rune/mic#_-miccol), calls binary function as _n_-ary function |
27| `foo:bar` | [`=<`](https://urbit.org/docs/hoon/reference/rune/tis#_-tisgal), composes two expressions, inverted |
28| `&#124;(foo bar baz)` | [`?&#124;`](https://urbit.org/docs/hoon/reference/rune/wut#_-wutbar), logical OR (loobean) |
29| `&(foo bar baz)` | [`?&`](https://urbit.org/docs/hoon/reference/rune/wut#_-wutpam), logical AND (loobean) |
30| `!foo` | [`?!`](https://urbit.org/docs/hoon/reference/rune/wut#_-wutzap), logical NOT (loobean) |
32##### Reading guide
34Headings contain runes, phonetics and tokens. Description contains a link to the
35docs and a short description of the rune. Both regular and irregular forms are given.
37Want to `Ctrl-f` to find out the meaning of something weird you saw? Search for `\symbol`. ie `\?` or `\=`. It'll show you to the irregular forms that uses that symbol.
39## `.` dot (nock)
41Anything Nock can do, Hoon can do also.
43### `.+` dotlus
45[docs](/docs/hoon/reference/rune/dot#dotlus) \\+
47`[%dtls p=atom]`: increment an atom with Nock 4.
49Regular: `.+(p)`
51Irregular: `+(p)`
53### `.=` dottis
55[docs](/docs/hoon/reference/rune/dot#dottis) \\=
57`[%dtts p=hoon q=hoon]`: test for equality with Nock 5.
59Regular: `.=(p q)`
61Irregular: `=(p q)`
63## `;` mic (make)
65Miscellaneous useful macros.
67### `;:` miccol
69[docs](/docs/hoon/reference/rune/mic#miccol) \\:
71`[%mccl p=hoon q=(list hoon)]`: call a binary function as an n-ary function.
73Regular: `;:(p q)`
75Irregular: `:(p q)`
77## `:` col (cells)
79The cell runes.
81### `:-` colhep
83[docs](/docs/hoon/reference/rune/col#colhep) \\[\\]\\^\\+\\\`\\~
85`[%clhp p=hoon q=hoon]`: construct a cell (2-tuple).
87Regular: `:-(p q)`
89Irregular:
91```
92 [a b] ==> :-(a b)
93[a b c] ==> [a [b c]]
94 a^b^c ==> [a b c]
95 a/b ==> [%a b]
96 a+b ==> [%a b]
97 `a ==> [~ a]
98 ~[a b] ==> [a b ~]
99 [a b]~ ==> [[a b] ~]
100```
102## `=` tis (flow)
104Flow hoons change the subject. All non-flow hoons (except cores) pass the subject down unchanged.
106### `=<` tisgal
108[docs](/docs/hoon/reference/rune/tis#tisgal) \\:
110`[%tsgl p=hoon q=hoon]`: compose two hoons, inverted.
112Regular: `=<(p q)`
114Irregular: `p:q`
116## `|` bar (core)
118[docs](/docs/hoon/reference/rune/bar) \\$
120Core hoons are flow hoon.
122Technically not irregular syntax, but worth mentioning.
124- `|= bartis`
125- `|. bardot`
126- `|- barhep`
127- `|* bartar`
129The above runes produce a core with a single arm, named `$` ("buc"). We can recompute this arm with changes, useful for recursion among other things. Commonly used with the irregular syntax for `%=`, `:make`, like so: `$()`.
131## `%` cen (call)
133The invocation family of runes.
135### `%=` centis
137[docs](/docs/hoon/reference/rune/cen#centis) \\(\\)
139`[%cnts p=wing q=(list (pair wing hoon))]`: take a wing with changes.
141Regular: `%=(p a 1)`
143Irregular: `p(a 1)`
145### `%~` censig
147[docs](/docs/hoon/reference/rune/cen#censig) \\~
149`[%cnsg p=wing q=hoon r=hoon]`: call with multi-armed door.
151Regular: `%~(p q r)`
153Irregular: `~(p q r)`
155### `%-` cenhep
157[docs](/docs/hoon/reference/rune/cen#cenhep) \\(\\)
159`[%cnhp p=hoon q=hoon]`: call a gate (function).
161Regular: `%-(p q)`
163Irregular: `(p q)`
165Note: `(p)` becomes `$:p` (`=<($ p)`), which behaves as you would expect (func call w/o args).
167## `$` buc (mold)
169A mold is a gate (function) that helps us build simple and rigorous data structures.
171### `$?` bucwut
173[docs](/docs/hoon/reference/rune/buc#bucwut) \\?
175`[%bcwt p=(list model)]`: mold which normalizes a general union.
177Regular: `$?(p)`
179Irregular: `?(p)`
181### `$_` buccab
183[docs](/docs/hoon/reference/rune/buc#buccab) \\\_
185`[%bccb p=value]`: mold which normalizes to an example.
187Regular: `$_(p)`
189Irregular: `_p`
191## `?` wut (test)
193Hoon has the usual branches and logical tests.
195### `?!` wutzap
197[docs](/docs/hoon/reference/rune/wut#wutzap) \\!
199`[%wtzp p=hoon]`: logical not.
201Regular: `?!(p)`
203Irregular: `!(p)`
205### `?&` wutpam
207[docs](/docs/hoon/reference/rune/wut#wutpam) \\&
209`[%wtpm p=(list hoon)]`: logical and.
211Regular: `?&(p)`
213Irregular: `&(p)`
215### `?|` wutbar
217[docs](/docs/hoon/reference/rune/wut#wutbar) \\|
219`[%wtbr p=(list hoon)]`: logical or.
221Regular: `?|(p)`
223Irregular: `|(p)`
225## `^` ket (cast)
227Lets us adjust types without violating type constraints.
229### `^:` ketcol
231[docs](/docs/hoon/reference/rune/ket#ketcol) \\,
233`[%ktcl p=spec]`: mold gate for type `p`.
235Regular: `^:(p)`
237Irregular: `,p`
239### `^-` kethep
241[docs](/docs/hoon/reference/rune/ket#kethep) \\\`
243`[%kthp p=model q=value]`: typecast by mold.
245Regular: `^-(p q)`
247Irregular: `` `p`q ``
249### `^*` kettar
251[docs](/docs/hoon/reference/rune/ket#kettar) \\\*
253`[%kttr p=spec]`: produce bunt value of mold.
255Regular: `^*(p)`
257Irregular: `*p`
259### `^=` kettis
261[docs](/docs/hoon/reference/rune/ket#kettis) \\=
263`[%ktts p=toga q=value]`: name a value.
265Regular: `^=(p q)`
267Irregular: `p=q`
269## Miscellaneous
271### Trivial molds
273- `*` noun.
274- `@` atom.
275- `^` cell.
276- `?` loobean.
277- `~` null.
279### Values
281\\~\\-\\.\\&\\|
283- `~` null.
284- `&` loobean true.
285- `|` loobean false.
286- `%a` constant `a`, where `a` can be an ((ir)regularly defined) atom or a symbol.
288See [%sand](/docs/hoon/reference/rune/constants#warm) for other irregular definitions of atoms.
290### List addressing
292- `&n` nth element of a list.
293- `|n` tail of list after nth element (i.e. n is the head).
295### Limbs
297[docs](/docs/hoon/reference/limbs/limb) \\+\\.\\^
299`[%limb p=(each @ud [p=@ud q=@tas])]`: attribute of subject.
301- `+15` is slot 15
302- `.` is the whole subject (slot 1)
303- `^a` is the `a` "of a higher scope", i.e. "resolve variable a, ignoring the first one found".
304- `^^p` even higher, etc.
305- 'Lark' syntax for slots / tree addressing:
307```
308+1
309+2 -
310+3 +
311+4 -<
312+5 ->
313+6 +<
314+7 +>
315+8 -<-
316...
317```
319### Wings
321[docs](content/docs/hoon/reference/limbs/wing)
322`[%wing p=(list limb)]`; a limb search path.
323`a.b` finds limb `a` within limb `b` ("var" `a` within "var" `b`).
325### Printing stuff
327- `<a b c>` prints a [tape](/docs/hoon/reference/stdlib/2q/#-tape).
328- `>a b c<` prints a [tank](/docs/hoon/reference/stdlib/2q/#-tank).
330## Commentary
332In our in-house examples throughout our documentation, we use irregular forms instead of regular for the sake of verbosity. But remember with irregular forms: everything is just runes! Like magic. In general, irregular forms (usually) read better, but of course regular forms provide more information about what you're doing by showing you the full rune. Of course, it's up to you, the Hoon programmer, as to whether or not you want to use these.