on 0d36dfd help sign in
urbit.org/docs/hoon/irregular.md
279 lines 6.6 kB history raw
1---
2navhome: /docs/
3sort: 22
4title: Irregular forms
5comments: true
6---
8## Irregular forms, a compilation
9##### `~palfun-foslup`
11<br />
13*Original `fora` post* [*here*](http://urbit.org/fora/posts/~2016.12.29..19.37.08..89d5~/).
15##### Reading guide
16Headings contain runes, phonetics and tokens. Description contains a link to the docs and a short description of the rune. Both regular (R) and irregular (I) forms are given.
18Want 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.
20## . dot (nock)
22Anything Nock can do, Hoon can do also.
24### .+ dotlus :bump
26[docs](https://urbit.org/docs/hoon/twig/dot-nock/lus-bump/) \\+
27`{$bump p/atom}`: increment an atom with Nock 4.
29R: `.+(p)`
30I: `+(p)`
32### .= dottis :same
34[docs](https://urbit.org/docs/hoon/twig/dot-nock/tis-same/) \\=
35`{$same p/seed q/seed}`: test for equality with Nock 5.
37R: `.=(p q)`
38I: `=(p q)`
40## ; sem (make)
42Miscellaneous useful macros.
44### ;: semcol :wad
46[docs](https://urbit.org/docs/hoon/twig/sem-make/col-wad/) \\:
47`{$wad p/seed q/(list seed)}`: call a binary function as an n-ary function.
49R: `;:(p q)`
50I: `:(p q)`
52## : col (cells)
54The cell twigs.
56### :- colhep :cons
58[docs](https://urbit.org/docs/hoon/twig/col-cell/hep-cons/) \\[\\]\\^\\+\\\`\\~
59`{$cons p/seed q/seed}`: construct a cell (2-tuple).
61R: `:-(p q)`
62I:
64```
65 [a b] ==> :-(a b)
66[a b c] ==> [a [b c]]
67 a^b^c ==> [a b c]
68 a+b ==> [%a b]
69 `a ==> [~ a]
70 ~[a b] ==> [a b ~]
71 [a b]~ ==> [[a b] ~]
72```
74## = tis (flow)
76Flow twigs change the subject. All non-flow twigs (except cores) pass the subject down unchanged.
78### =< tisgal :rap
80[docs](https://urbit.org/docs/hoon/twig/tis-flow/gal-rap/) \\:
81`{$rap p/seed q/seed}`: compose two twigs, inverted.
83R: `=<(p q)`
84I: `p:q`
86## | bar (core)
88[docs](https://urbit.org/docs/hoon/twig/bar-core/) \\$
89Core twigs are flow twigs.
91Technically not irregular syntax, but worth mentioning.
93* `|= bartis :gate`
94* `|. bardot :trap`
95* `|- barhep :loop`
96* `|* bartar :gill`
98The above runes produce a core with a single arm, named `$` (or `:moar`). We can recompute this arm with changes, useful for recursion among other things. Commonly used with the irregular syntax for `%=`, `:make`, like so: `$()`.
100## % cen (call)
102The invocation family of twigs.
104### %= centis :make
106[docs](https://urbit.org/docs/hoon/twig/cen-call/tis-make/) \\(\\)
107`{$make p/wing q/(list (pair wing seed))}`: take a wing with changes.
109R: `%=(p a 1)`
110I: `p(a 1)`
112### %~ censig :open
114[docs](https://urbit.org/docs/hoon/twig/cen-call/sig-open/) \\~
115`{$cnsg p/wing q/seed r/seed}`: call with multi-armed door.
117R: `%~(p q r)`
118I: `~(p q r)`
120### %- cenhep :call
122[docs](https://urbit.org/~~/docs/hoon/twig/cen-call/hep-call/) \\(\\)
123`{$call p/seed q/seed}`: call a gate (function).
125R: `%-(p q)`
126I: `(p q)`
128Note: `(p)` becomes `$:p` (`=<($ p)`), which behaves as you would expect (func call w/o args).
130## $ buc (mold)
132A mold is a gate (function) that helps us build simple and rigorous data structures.
134### $: buccol :bank
136[docs](https://urbit.org/docs/hoon/twig/buc-mold/col-bank/) \\{\\}
137`{$bank p/(list moss)}`: form a mold which recognizes a tuple.
139R: `$:(p q)`
140I: `{p q}`
142### $= buctis :coat
144[docs](https://urbit.org/docs/hoon/twig/buc-mold/tis-coat/) \\/
145`{$coat p/@tas q/moss}`: mold which wraps a face around another mold.
147R: `$=(p q)`
148I: `p/q`
150### $? bucwut :pick
152[docs](https://urbit.org/docs/hoon/twig/buc-mold/wut-pick/) \\?
153`{$pick p/(list moss)}`: mold which normalizes a general union.
155R: `$?(p)`
156I: `?(p)`
158### $_ buccab :shoe
160[docs](https://urbit.org/docs/hoon/twig/buc-mold/cab-shoe/) \\_
161`{$shoe p/seed}`: mold which normalizes to an example.
163R: `$_(p)`
164I: `_p`
166## ? wut (test)
168Hoon has the usual branches and logical tests.
170### ?! wutzap :not
172[docs](https://urbit.org/docs/hoon/twig/wut-test/zap-not/) \\!
173`{$not p/seed}`: logical not.
175R: `?!(p)`
176I: `!(p)`
178### ?& wutpam :and
180[docs](https://urbit.org/docs/hoon/twig/wut-test/pam-and/) \\&
181`{$and p/(list seed)}`: logical and.
183R: `?&(p)`
184I: `&(p)`
186### ?& wutbar :or
188[docs](https://urbit.org/docs/hoon/twig/wut-test/bar-or/) \\|
189`{$or p/(list seed)}`: logical or.
191R: `?|(p)`
192I: `|(p)`
194## ^ ket (cast)
196Lets us adjust spans without violating type constraints.
198### ^- kethep :cast
200[docs](https://urbit.org/docs/hoon/twig/ket-cast/hep-cast/) \\\`
201`{$cast p/moss q/seed}`: typecast by mold.
203R: `^-(p q)`
204I: ```p`q``
206### ^= kettis :name
208[docs](https://urbit.org/docs/hoon/twig/ket-cast/tis-name/) \\=
209`{$name p/toga q/seed}`: name a value.
211R: `^=(p q)`
212I: `p=q`
214## Miscellaneous
216### Trivial molds
218\\*\\^\\?
220* `*` noun.
221* `^` cell.
222* `?` loobean.
223* `$~` null.
225### Values
227\\~\\-\\.\\&\\|
229* `~` null.
230* `&` loobean true.
231* `|` loobean false.
232* `%a` constant `a`, where `a` can be an ((ir)regularly defined) atom or a symbol.
234See [:sand](https://urbit.org/docs/hoon/twig/atom/sand/) for other irregular definitions of atoms.
236### List addressing
237* `&n` nth element of a list.
238* `|n` tail of list after nth element (i.e. n is the head).
240### Limbs :limb
242[docs](https://urbit.org/docs/hoon/twig/limb/limb/) \\+\\.\\^
243`{$limb p/(each @ud {p/@ud q/@tas})}`: attribute of subject.
245* `+15` is slot 15
246* `.` is the whole subject (slot 1)
247* `^a` is the `a` "of a higher scope", i.e. "resolve variable a, ignoring the first one found".
248* `^^p` even higher, etc.
249* 'Lark' syntax for slots / tree addressing:
250```
251+1
252+2 -
253+3 +
254+4 -<
255+5 ->
256+6 +<
257+7 +>
258+8 -<-
259...
260```
263### Wings :wing
265[docs](https://urbit.org/~~/docs/hoon/twig/limb/wing/) \\.
266`{$wing p/(list limb)`; a limb search path.
268`a.b` finds limb `a` within limb `b` ("var" `a` within "var" `b`).
270### Printing stuff
272* `<a b c>` prints a [tape](https://urbit.org/docs/hoon/library/2q/#-tape).
273* `>a b c<` prints a [tank](https://urbit.org/docs/hoon/library/2q/#-tank).
275## Commentary
277 In 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.
279 ##### If we missed any, or if you saw something weird that's not in here, feel free to comment below!