on 3c19574 help sign in
urbit.org/docs/hoon/irregular.md
263 lines 5.4 kB history raw
1---
2navhome: /docs/
3sort: 25
4title: Irregular forms
5comments: true
6---
8## Irregular forms, a compilation
9##### `~palfun-foslup`
11<br />
13*Original Fora post* [*here*](https://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
26[docs](../rune/dot/lus/) \\+
27`[%dtls p=atom]`: increment an atom with Nock 4.
29R: `.+(p)`
30I: `+(p)`
32### .= dottis
34[docs](../rune/dot/tis/) \\=
35`[%dtls p=hoon q=hoon]`: test for equality with Nock 5.
37R: `.=(p q)`
38I: `=(p q)`
40## ; sem (make)
42Miscellaneous useful macros.
44### ;: semcol
46[docs](../rune/sem/col/) \\:
47`[%smcl p=hoon q=(list hoon)]`: call a binary function as an n-ary function.
49R: `;:(p q)`
50I: `:(p q)`
52## : col (cells)
54The cell runes.
56### :- colhep
58[docs](../rune/col/hep/) \\[\\]\\^\\+\\\`\\~
59`[%clhp p=hoon q=hoon]`: 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 hoons change the subject. All non-flow hoons (except cores) pass the subject down unchanged.
78### =< tisgar
80[docs](../rune/tis/gal/) \\:
81`[%tsgl p=hoon q=hoon]`: compose two hoons, inverted.
83R: `=<(p q)`
84I: `p:q`
86## | bar (core)
88[docs](../rune/bar/) \\$
89Core hoons are flow hoon.
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 `$` ("buc"). 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 runes.
104### %= centis
106[docs](../rune/cen/tis/) \\(\\)
107`[%cnts p=wing q=(list (pair wing hoon))]`: take a wing with changes.
109R: `%=(p a 1)`
110I: `p(a 1)`
112### %~ censig
114[docs](../rune/cen/sig/) \\~
115`[%cnsg p=wing q=hoon r=hoon]`: call with multi-armed door.
117R: `%~(p q r)`
118I: `~(p q r)`
120### %- cenhep
122[docs](../rune/cen/hep/) \\(\\)
123`[%cnhp p=hoon q=hoon]`: 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### $? bucwut
136[docs](../rune/buc/wut/) \\?
137`[%bcwt p=(list model)]`: mold which normalizes a general union.
139R: `$?(p)`
140I: `?(p)`
142### $_ buccab
144[docs](../rune/buc/cab/) \\_
145`[%bccb p=value]`: mold which normalizes to an example.
147R: `$_(p)`
148I: `_p`
150## ? wut (test)
152Hoon has the usual branches and logical tests.
154### ?! wutzap
156[docs](../rune/wut/zap/) \\!
157`[%wtzp p=hoon]`: logical not.
159R: `?!(p)`
160I: `!(p)`
162### ?& wutpam
164[docs](../rune/wut/pam/) \\&
165`[%wtpm p=(list hoon)]`: logical and.
167R: `?&(p)`
168I: `&(p)`
170### ?| wutbar
172[docs](../rune/wut/bar/) \\|
173`[%wtbr p=(list hoon)]`: logical or.
175R: `?|(p)`
176I: `|(p)`
178## ^ ket (cast)
180Lets us adjust types without violating type constraints.
182### ^- kethep
184[docs](../rune/ket/hep/) \\\`
185`[%kthp p=model q=value]`: typecast by mold.
187R: `^-(p q)`
188I: `` `p`q ``
190### ^= kettis
192[docs](../rune/ket/tis/) \\=
193`[%ktts p=toga q=value]`: name a value.
195R: `^=(p q)`
196I: `p=q`
198## Miscellaneous
200### Trivial molds
202\\*\\^\\?
204* `*` noun.
205* `^` cell.
206* `?` loobean.
207* `~` null.
209### Values
211\\~\\-\\.\\&\\|
213* `~` null.
214* `&` loobean true.
215* `|` loobean false.
216* `%a` constant `a`, where `a` can be an ((ir)regularly defined) atom or a symbol.
218See [%sand](../atom/sand/) for other irregular definitions of atoms.
220### List addressing}
221* `&n` nth element of a list.
222* `|n` tail of list after nth element (i.e. n is the head).
224### Limbs
226[docs](../limb/limb/) \\+\\.\\^
227`[%limb p=(each @ud [p=@ud q=@tas])]`: attribute of subject.
229* `+15` is slot 15
230* `.` is the whole subject (slot 1)
231* `^a` is the `a` "of a higher scope", i.e. "resolve variable a, ignoring the first one found".
232* `^^p` even higher, etc.
233* 'Lark' syntax for slots / tree addressing:
234```
235+1
236+2 -
237+3 +
238+4 -<
239+5 ->
240+6 +<
241+7 +>
242+8 -<-
243...
244```
247### Wings
249[docs](../limb/wing/) \\.
250`[%wing p=(list limb)]`; a limb search path.
252`a.b` finds limb `a` within limb `b` ("var" `a` within "var" `b`).
254### Printing stuff
256* `<a b c>` prints a [tape](../library/2q/#-tape).
257* `>a b c<` prints a [tank](../library/2q/#-tank).
259## Commentary
261 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.
263 ##### If we missed any, or if you saw something weird that's not in here, feel free to comment below!