@@ -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).
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.
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.
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.
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
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.
28− ~fintud-macrep:dojo> |mount %
31+### Network install
30−Then, copy the example into it
33+In your urbit's `:dojo`, run the command:
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
41+ sync succeeded from %examples on ~ropmev-pocseb to %examples
43+In which case, next run the commands:
45+ ~your-urbit:dojo> =dir /=examples=
46+ ~your-urbit:dojo/examples> |serve %/web
47+ ~your-urbit:dojo/examples> |mount %
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.
54+In your urbit's `:dojo`:
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 %
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`.
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*):
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
71+Your `%clay` filesystem should acknowledge the newly added files.
35Run an example to ensure it worked:
75Run an example to ensure it worked:
37− ~fintud-macrep:dojo> +examples-euler1
77+ ~fintud-macrep:dojo> +project-euler/p1
@@ -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.
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`):
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
56− :::: /hoon/euler1/examples/gen
95+ :: run in dojo with:
96+ :: ~your-urbit:dojo/examples> +project-euler/p1
98+ :::: /===/gen/project-euler/p1/hoon
58− :- %say |= *
102+ :- %say |= *
60 =< (sum 1.000)
104 =< (sum 1.000)
68− |- ^- @u
110+ |- ^- @u
69 ?: (lth a b)
111 ?: (lth a b)
71 (add b $(b (add 3 b)))
113 (add b $(b (add 3 b)))
77 ?: (lte a b)
119 ?: (lte a b)
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)))
85− (add (five a) (three a))
127+ (add (five a) (three a))
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.
94−### Lines 1-11:
136+### Lines 1-13:
96Any line that begins with `::` is a comment.
138Any line that begins with `::` is a comment.
@@ -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 `==`).
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:
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.
142Using this scheme, we would pronounce `?:` as 'wutcol'.
184Using this scheme, we would pronounce `?:` as 'wutcol'.
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`:
148−`{$if p/twig q/twig r/twig} :: ?: if/then/else`
152− ?:(=(1 2) 'this is true' 'this is false')
157− :if(=(1 2) 'this is true' 'this is false')
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 `--`.
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`
179 (add (five a) (three a))
205 (add (five a) (three a))
@@ -187,7 +213,7 @@ like a lambda in lisp. It takes two children:
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`.
193### ++ three
219### ++ three