11We've used predefined marks already, but we haven't yet created
12our own marks. Let's write a sample mark of our own, then chain
13it together with some preexisting ones to have fun with type
16Let's make a small "cord" mark. "Cord" is a name we use for `@t`
17text, but there's no predefined mark for it. Let's put the following code in:
25 ++ atom |=(arg=@ `@t`(scot %ud arg))
34`/? 314` is the required
35version number, just like in apps. After that everything's in a
36`|_`, which is a `|%` core, but with input arguments. In our
37case, the argument is the marked data.
39There are three possible top-level arms in the `|_` core,
40`++grab`, `++grow`, and `++grad` (which is used for revision
41control, covered elsewhere). `++grab` specifies
42functions to convert from another mark to the current mark.
43`++grow` specifies how to convert from the current mark to
46In our case, we only define one arm in `++grab`, namely `++atom`.
47This allows us to convert any atom to a cord. `++scot` is a
48standard library function in `hoon.hoon` which pretty-prints
49atoms of various types. We want to treat the atom as an
50unsigned decimal number, so we give `%ud` and the given argument
51to `++scot`. Thus, the form of an arm in `++grab` is
52`|=(other-mark-type this-mark-value)`.
54In `++grow`, we just convert to the `md` mark, which is just a
55`@t` internally, but it has fancy conversion functions to things
56like html. `++md` isn't a function because the "argument" is
57already a `@t`, so we can just produce the new value directly.
59Let's play around a bit with this mark. First, let's take a
60marked atom and convert it to our new mark.
63~fintud-macrep:dojo> &atom 9
66~fintud-macrep:dojo> &cord &atom 9
69~fintud-macrep:dojo> &cord &atom &cord &atom 9
73ASCII 9 is 57. There's no requirement, implicit or otherwise,
74that conversions back and forth between marks be inverses of each
75other. These are semantic conversions, in that they refer to the
76same concept. They're not isomorphisms.
78Let's play around a little more:
81~fintud-macrep:dojo> &md &cord &atom 17
84~fintud-macrep:dojo> &hymn &md &cord &atom 17
87 [[%body ~] [g=[n=%pre a=~] c=~[[g=[n=%$ a=~[[n=%$ v="17"]]] c=~]]] ~]
92That was exciting. If you squint at that, it looks an
93awful lot like html. Our value `17` is still in there, in the
94body. `urb` is the mark we render most web pages to. It makes
95sure you have a complete skeleton of a web page. Of course, by
96the time this gets to the web page, it's plain html. Let's do
97the final step in the conversion.
100~fintud-macrep:dojo> &mime &hymn &md &cord &atom 17
101[[%text %html ~] p=52 q='<html><head></head><body><pre>17</pre></body></html>']
104This is a mime-typed octet stream with type `/text/html`, length
105121 bytes, and our lowly number `17` rendered to a web page.
106`cord` was just one step in the chain.
108Of course, arvo can infer some parts of this chain:
111~fintud-macrep:dojo> &cord 17
115Likewise, `md` is the only way to get from `cord` to `hymn`, so
116that can be omitted. If we omit the `hymn`, though, we get:
119~fintud-macrep:dojo> &mime &cord 17
120[[%text %x-markdown ~] p=2 q='17']
123Here, we converted straight from `cord` to `md` to `mime`. Arvo
124decided that was the most straightforward conversion, but it
125gives a different result than passing it through the `hymn`
128The minimal correct input, then, is `&mime &hymn &cord &atom 17`.
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