+20
Janet/chapter6/hosts.janet
+20
Janet/chapter6/hosts.janet
···
···
1
+
(def hosts [
2
+
{:name "claudius"
3
+
:ip "45.63.9.183"
4
+
:online true
5
+
:services
6
+
[{:name "janet.guide"}
7
+
{:name "bauble.studio"}
8
+
{:name "ianthehenry.com"}]}
9
+
{:name "caligula"
10
+
:ip "45.63.9.184"
11
+
:online false
12
+
:services [{:name "basilica.horse"}]}])
13
+
14
+
(def services
15
+
(seq [host :in hosts
16
+
:when (host :online)
17
+
service :pairs (host :services)]
18
+
service))
19
+
20
+
(pp services)
+40
Janet/chapter6/loop.janet
+40
Janet/chapter6/loop.janet
···
···
1
+
(def hosts [
2
+
{:name "claudius"
3
+
:ip "45.63.9.183"
4
+
:online true
5
+
:services
6
+
[{:name "janet.guide"}
7
+
{:name "bauble.studio"}
8
+
{:name "ianthehenry.com"}]}
9
+
{:name "caligula"
10
+
:ip "45.63.9.184"
11
+
:online false
12
+
:services [{:name "basilica.horse"}]}])
13
+
14
+
(each host hosts
15
+
(if (host :online)
16
+
(each service (host :services)
17
+
(print (service :name)))))
18
+
19
+
(loop [host :in hosts
20
+
:when (host :online)
21
+
service :in (host :services)]
22
+
(print (service :name)))
23
+
24
+
(print)
25
+
26
+
(each host hosts
27
+
(if (host :online)
28
+
(let [ip (host :ip)]
29
+
(eachp [service-name available] (host :services)
30
+
(if available
31
+
(for instance 0 3
32
+
(pp [ip service-name instance])))))))
33
+
34
+
(loop [host :in hosts
35
+
:when (host :online)
36
+
:let [ip (host :ip)]
37
+
[service-name available] :pairs (host :services)
38
+
:when available
39
+
instance :range [0 3]]
40
+
(pp [ip service-name instance]))
+5
Janet/chapter7/helpers.janet
+5
Janet/chapter7/helpers.janet
+20
Janet/chapter7/main.janet
+20
Janet/chapter7/main.janet
···
···
1
+
(defn choose [rng selections]
2
+
(def index (math/rng-int rng (length selections)))
3
+
(in selections index))
4
+
5
+
(defn verbosify [rng word]
6
+
(choose rng
7
+
(case word
8
+
"quick" ["alacritous" "expeditious"]
9
+
"lazy" ["indolent" "lackadaisical" "languorous"]
10
+
"jumps" ["gambols"]
11
+
[word])))
12
+
13
+
(defn main [&]
14
+
(def rng (math/rng (os/time)))
15
+
(as-> stdin $
16
+
(file/read $ :all)
17
+
(string/split " " $)
18
+
(map (partial verbosify rng) $)
19
+
(string/join $ " ")
20
+
(prin $)))
+6
Janet/chapter7/private.janet
+6
Janet/chapter7/private.janet