on 514b5fc help sign in
224 lines 4.6 kB history raw
1+++
2title = "Nock . ('dot')"
3weight = 3
4template = "doc.html"
5aliases = ["docs/reference/hoon-expressions/rune/dot/"]
6+++
8Anything Nock can do, Hoon can do also. These runes are used for carrying out Nock operations in Hoon.
10## Runes
12### `.^` "dotket"
14`[%dtkt p=spec q=hoon]`: load from the Arvo namespace with a fake Nock instruction: 'Nock `12`''.
16##### Produces
18The noun `q`, cast to the type `p`.
20##### Discussion
22Nock has no `12` instruction! But the virtual Nock
23used to run userspace code does. Nock `12` loads from a
24typed immutable namespace defined by its virtual context.
26Ordinarily a Hoon expression has access to no information but whatever can be found in the subject. The one exception is with the `.^` rune. It essentially allows you to request information from one of the Arvo vanes (modules).
28`.^` checks that the type of the value retrieved from Arvo nests under `p`. `q` is a `path` which includes information about which vane is being queried, and what sort of information is requested.
30In principle `.^` takes two subexpressions, but in practice `q` is often given in two parts: the first part includes the vane to be queried (e.g., `%a` for Ames, `%b` for Behn, `%c` for Clay, etc.) and the kind of request. The second part is a path that corresponds to the kind of request.
32##### Examples
34In the dojo we can ask Clay -- the Arvo filesystem -- for a listing of the files at our current path, `%`:
36```
37> .^(arch %cy %)
38[ fil=~
39 dir
40 { [p=~.web q=~]
41 [p=~.LICENSE q=~]
42 [p=~.app q=~]
43 [p=~.lib q=~]
44 [p=~.sec q=~]
45 [p=~.sys q=~]
46 [p=~.ren q=~]
47 [p=~.sur q=~]
48 [p=~.tests q=~]
49 [p=~.mar q=~]
50 [p=~.gen q=~]
51 }
53```
55The `%c` is for Clay, and the `y` is for the request type. `arch` is the type of the listing. See `gen/cat.hoon` to see how this information is printed more prettily.
57The `%` is for the current path in the dojo:
59```
60> `path`%
61/~zod/base/~2018.9.20..23.05.35..0231
62```
64You can modify the time of the file listing quite simply and ask for a listing from 5 hours ago. (Remember that Clay is a revision-controlled file system.)
66```
67> .^(arch %cy /(scot %p our)/base/(scot %da (sub now ~h5)))
68[ fil=~
69 dir
70 { [p=~.web q=~]
71 [p=~.LICENSE q=~]
72 [p=~.app q=~]
73 [p=~.lib q=~]
74 [p=~.sec q=~]
75 [p=~.sys q=~]
76 [p=~.ren q=~]
77 [p=~.sur q=~]
78 [p=~.tests q=~]
79 [p=~.mar q=~]
80 [p=~.gen q=~]
81 }
83```
85`our` is the value for your ship's name.
87### `.+` "dotlus"
89`[%dtls p=hoon]`: increment an atom with Nock `4`.
91##### Produces
93`p` plus `1` if `p` is an atom; otherwise, crashes. The product atom has no aura.
95##### Syntax
97Regular: **1-fixed**.
99Irregular: `+(6)` is `.+(6)`.
101##### Examples
103```
104> .+(6)
107> +(6)
110> +(%foo)
1117.303.015
113> +([1 2])
114nest-fail
115```
117### `.*` "dottar"
119`[%dttr p=hoon q=hoon]`: evaluate with Nock `2`.
121##### Produces
123Nock of formula `q` and subject `p`, with type `%noun`.
125##### Syntax
127Regular: **2-fixed**.
129##### Discussion
131`.*(p q)` is used to run Nock formula `q` on the subject `p` from within Hoon.
133Keep in mind that `p` and `q` can be arbitrary Hoon expressions, as long as they evaluate to the appropriate nouns for Nock evaluation.
135Note also that `.*` ("dottar") can be used to bypass the type system. It's
136therefore possible to use Hoon as a typeless language.
138##### Examples
140```
141> .*([20 30] [0 2])
14220
144> .*(33 [4 0 1])
14534
147> .*(|.(50) [9 2 0 1])
14850
150> .*(12 [7 [`1 [4 `1]] [`2 `3 `2]])
151[12 13 12]
153> .*(~ [5 1^4 [4 1^3]])
156> .*(~ [5 1^5 [4 1^3]])
158```
160### `.=` "dottis" {#dottis}
162`[%dtts p=hoon q=hoon]`: test for equality with Nock `5`.
164##### Produces
166`%.y` if `p` equals `q`; otherwise `%.n`.
168##### Syntax
170Regular: **2-fixed**.
172Irregular: `=(a b)` is `.=(a b)`.
174##### Discussion
176The test for equality includes a type check. Either the type of `p` must nest under the type of `q`, or _vice versa_. Otherwise the result is a crash.
178Like Nock equality, `.=` ("dottis") tests whether two nouns are the same,
179ignoring invisible pointer structure. Because in a conventional
180noun implementation each noun has a lazy short hash, comparisons
181are fast unless the hash needs to be computed, or we are comparing
182separate copies of identical nouns. (Comparing large duplicates
183is a common cause of performance bugs.)
185##### Examples
187```
188> .=(0 0)
189%.y
191> =(0 0)
192%.y
194> .=(1 2)
195%.n
197> =(1 2)
198%.n
200> =(12 [12 14])
201nest-fail
202```
204### `.?` "dotwut"
206`[%dtwt p=hoon]`: test for cell or atom with Nock `3`.
208##### Produces
210`%.y` if `p` is a cell; otherwise `%.n`.
212##### Syntax
214Regular: **1-fixed**.
216##### Examples
218```
219> .?(42)
220%.n
222> .?([42 43])
223%.y
224```