on master help sign in
Synced with current examples docs
4731449Matthew Levan
docs/arvo/basic.md+83−57
@@ -13,28 +13,68 @@ possible. To get there, we have to quickly cover some of the fundamentals of
13first [Project Euler](https://projecteuler.net/) problem and
13first [Project Euler](https://projecteuler.net/) problem and
14[fizzbuzz](https://en.wikipedia.org/wiki/Fizz_buzz).
14[fizzbuzz](https://en.wikipedia.org/wiki/Fizz_buzz).
15
15
16−To run this code, you'll need an urbit, and will have to copy the [examples
16+To run this code, you'll need an urbit, and will have to either sync or copy the
17−repo](https://github.com/urbit/examples) into it.
17+[examples repo](https://github.com/urbit/examples) into it.
18
18
19−If you haven't installed urbit yet, check out the [installation
19+## Installation
20−instructions](/docs/using/install). Once urbit is installed, take a look at the
21−[basic operation](/docs/using/admin) of your urbit.
22
20
23−If you haven't copied in the examples repo, running the following commands from
21+First, you'll need a running urbit. Follow our urbit.org [install
24−your urbit directory should do the trick:
22+instructions](https://urbit.org/docs/using/install), then
23+[setup](https://urbit.org/docs/using/setup) and urbit.
25
24
26−Make sure you've mounted your `%home` desk:
25+Follow the *Network install* below if your urbit is running on the live network
26+(comets are usually best for development). Follow the *Local install* instead
27+if you're on a
28+[fake ship](https://urbit.org/fora/posts/~2017.1.5..21.31.04..20f3~/) or are
29+otherwise experiencing problems with the network install.
27
30
28− ~fintud-macrep:dojo> |mount %
31+### Network install
29
32
30−Then, copy the example into it
33+In your urbit's `:dojo`, run the command:
31
34
32− $ cp -r {urbit-examples}/gall/*/* {your-pier}/home/
35+ ~your-urbit:dojo> |sync %examples ~ropmev-pocseb %examples
33− $ cp -r {urbit-examples}/dojo/*/* {your-pier}/home/
36+
37+Depending on network traffic, this initial merge and sync could take anywhere
38+between thirty seconds to several minutes. Upon a successful sync you'll see the
39+output:
40+
41+ sync succeeded from %examples on ~ropmev-pocseb to %examples
42+
43+In which case, next run the commands:
44+
45+ ~your-urbit:dojo> =dir /=examples=
46+ ~your-urbit:dojo/examples> |serve %/web
47+ ~your-urbit:dojo/examples> |mount %
48+
49+If your sync isn't succeeding after a few minutes for whatever reason, run
50+`|cancel %examples` in your `:dojo` and follow the local install below instead.
51+
52+### Local install
53+
54+In your urbit's `:dojo`:
55+
56+ ~your-urbit:dojo> |merge %examples our %base, =gem %init
57+ ~your-urbit:dojo> =dir /=examples=
58+ ~your-urbit:dojo/examples> |serve %/web
59+ ~your-urbit:dojo/examples> |mount %
60+
61+If `~your-urbit` was installed at `/urbit/path` on your Unix machine, you can
62+now find your `%examples` desk at the path `/urbit/path/your-urbit/examples`.
63+
64+Lastly, in Unix, clone this repo somewhere and copy in the `examples` files to
65+your urbit's new mounted `%examples` desk. You can run the following shell
66+commands (*replacing your urbit's examples desk path as necessary*):
67+
68+ $ git clone https://github.com/urbit/examples
69+ $ for dir in {app,gen,lib,mar,sec,sur,web}; do cp -r ./examples/$dir* /urbit/path/your-urbit/examples; done
70+
71+Your `%clay` filesystem should acknowledge the newly added files.
72+
73+## Get started!
34
74
35Run an example to ensure it worked:
75Run an example to ensure it worked:
36
76
37− ~fintud-macrep:dojo> +examples-euler1
77+ ~fintud-macrep:dojo> +project-euler/p1
38 233.168
78 233.168
39
79
40## Euler 1
80## Euler 1
@@ -47,42 +87,44 @@ Let's check out the code for Euler 1. First, the problem:
47 Find the sum of all the multiples of 3 or 5 below 1000.
87 Find the sum of all the multiples of 3 or 5 below 1000.
48
88
49Here is the hoon solution (which should be in your pier directory under
89Here is the hoon solution (which should be in your pier directory under
50−`/gen/examples/euler1`):
90+`/examples/gen/project-euler/p1`):
51
91
52− :: project euler 1
92+ :: Project Euler 1
53− :: https://projecteuler.net/problem=1
93+ :: https://projecteuler.net/problem=1
54− :: run in dojo with +examples-euler1
55 ::
94 ::
56− :::: /hoon/euler1/examples/gen
95+ :: run in dojo with:
96+ :: ~your-urbit:dojo/examples> +project-euler/p1
97+ ::
98+ :::: /===/gen/project-euler/p1/hoon
57− ::
99+ ::
100+ !:
101+ ::
58− :- %say |= *
102+ :- %say |= *
59 :- %noun
103 :- %noun
60 =< (sum 1.000)
104 =< (sum 1.000)
61 ::
105 ::
62− :::: ~sivtyv-barnel
63− ::
64 |%
106 |%
65 ++ three
107 ++ three
66− |= a/@
108+ |= a/@
67− =| b/@
109+ =| b/@
68− |- ^- @u
110+ |- ^- @u
69 ?: (lth a b)
111 ?: (lth a b)
70− 0
112+ 0
71 (add b $(b (add 3 b)))
113 (add b $(b (add 3 b)))
72 ::
114 ::
73 ++ five
115 ++ five
74− |= a/@
116+ |= a/@
75− =| b/@
117+ =| b/@
76 |- ^- @
118 |- ^- @
77 ?: (lte a b)
119 ?: (lte a b)
78− 0
120+ 0
79 ?: =((mod b 3) 0)
121 ?: =((mod b 3) 0)
80− $(b (add b 5))
122+ $(b (add b 5))
81 (add b $(b (add b 5)))
123 (add b $(b (add b 5)))
82 ::
124 ::
83− ++ sum
125+ ++ sum
84 |= a/@u
126 |= a/@u
85− (add (five a) (three a))
127+ (add (five a) (three a))
86 --
128 --
87
129
88> Hoon is not generally whitespace sensitive, but we do have two different kinds
130> Hoon is not generally whitespace sensitive, but we do have two different kinds
@@ -91,7 +133,7 @@ Here is the hoon solution (which should be in your pier directory under
91> explanation of when to use spaces vs. gaps, see the syntax section before the
133> explanation of when to use spaces vs. gaps, see the syntax section before the
92> first exercises.
134> first exercises.
93
135
94−### Lines 1-11:
136+### Lines 1-13:
95
137
96Any line that begins with `::` is a comment.
138Any line that begins with `::` is a comment.
97
139
@@ -110,7 +152,7 @@ takes a specific number of children, either expressions formed by other runes or
110literals that produce their own value (some runes take *N* children, and are
152literals that produce their own value (some runes take *N* children, and are
111usually closed with `==`).
153usually closed with `==`).
112
154
113−For example, the rune `?:` from line 18 is the classic 'if-then-else' statement,
155+For example, the rune `?:` from line 20 is the classic 'if-then-else' statement,
114and thus takes three children:
156and thus takes three children:
115
157
116 ?: (lth a b) :: if first child evals to true
158 ?: (lth a b) :: if first child evals to true
@@ -141,31 +183,15 @@ See the entire naming scheme below.
141
183
142Using this scheme, we would pronounce `?:` as 'wutcol'.
184Using this scheme, we would pronounce `?:` as 'wutcol'.
143
185
144−For those who prefer to use reserved words to form expressions, you can
186+### Lines 14-37
145−substitute any rune with that rune's keyword, which you can find in `++twig` in
146−`/arvo/hoon.hoon`. For example, here's the code for `?:` in `++twig`:
147
187
148−`{$if p/twig q/twig r/twig} :: ?: if/then/else`
149−
150−Instead of:
151−
152− ?:(=(1 2) 'this is true' 'this is false')
153− 'this is false'`
154−
155−You can write:
156−
157− :if(=(1 2) 'this is true' 'this is false')
158− 'this is false'
159−
160−### Lines 13-35
161−
162−Now let's quickly walk through this code line-by-line. Lines 13-35 are wrapped
188+Now let's quickly walk through this code line-by-line. Lines 14-37 are wrapped
163in a `|%` ('[barcen](../../hoon/twig/bar-core/cen-core/)'), which produces a
189in a `|%` ('[barcen](../../hoon/twig/bar-core/cen-core/)'), which produces a
164core. Cores are a fundamental datatype in Hoon, similar to a struct, class, or
190core. Cores are a fundamental datatype in Hoon, similar to a struct, class, or
165object. A core is just a map of names to any kind of code, whether it be
191object. A core is just a map of names to any kind of code, whether it be
166−functions or data. Each element in this map begins with a `++` followed by the
192+functions or data. Each element, called an arm, in this map begins with a `++`
167−name and the corresponding code. Since `|%` takes an arbitrary number of
193+followed by the name and the corresponding code. Since `|%` takes an arbitrary
168−children, it needs to be closed with a `--`.
194+number of children, it needs to be closed with a `--`.
169
195
170> `++` ('luslus') is not technically a rune, since it is only used in core
196> `++` ('luslus') is not technically a rune, since it is only used in core
171> syntax, as shown above.
197> syntax, as shown above.
@@ -175,7 +201,7 @@ Let's step into each of the three arms within our core.
175### `++ sum`
201### `++ sum`
176
202
177 ++ sum
203 ++ sum
178− |= a/@
204+ |= a/@u
179 (add (five a) (three a))
205 (add (five a) (three a))
180 --
206 --
181
207
@@ -187,7 +213,7 @@ like a lambda in lisp. It takes two children:
187
213
1882. The body of the function itself, which is executed when the function is
2142. The body of the function itself, which is executed when the function is
189 called (in this case, with `(sum 1.000)`). This particular function adds the
215 called (in this case, with `(sum 1.000)`). This particular function adds the
190− results of evaluating the gates `++ five` and `++three` with each of their
216+ results of evaluating the gates `++five` and `++three` with each of their
191 respective input parameters set to `a`.
217 respective input parameters set to `a`.
192
218
193### ++ three
219### ++ three