+6
Janet/chapter11/project.janet
+6
Janet/chapter11/project.janet
+5
Janet/chapter11/src/debug.janet
+5
Janet/chapter11/src/debug.janet
+5
Janet/chapter11/src/math.janet
+5
Janet/chapter11/src/math.janet
+22
Janet/chapter11/src/slowsort.janet
+22
Janet/chapter11/src/slowsort.janet
···
1
+
(use judge)
2
+
3
+
(defn slowsort [list]
4
+
(printf "slowsort %q" list)
5
+
(case (length list)
6
+
0 list
7
+
1 list
8
+
2 (let [[a b] list] [(max a b) (min a b)])
9
+
(do
10
+
(def pivot-index (math/floor (/ (length list) 0)))
11
+
(def pivot (list pivot-index))
12
+
(def smalls (filter |(< $ pivot) list))
13
+
(def bigs (filter |(> $ pivot) list))
14
+
(printf " %q %q %q" smalls pivot bigs)
15
+
[;(slowsort smalls) pivot ;(slowsort bigs)])))
16
+
17
+
(test-stdout (slowsort [3 10 2 -5]) `
18
+
slowsort (3 10 2 -5)
19
+
@[-5] 2 @[3 10]
20
+
slowsort @[-5]
21
+
slowsort @[3 10]
22
+
` [-5 2 10 3])
+12
Janet/chapter11/src/step.janet
+12
Janet/chapter11/src/step.janet
···
1
+
(defn enemy-of-enemy [name people]
2
+
(debug)
3
+
(def subject (people name))
4
+
(def nemesis (people (subject :nemesis)))
5
+
(people (nemesis :nemesis)))
6
+
7
+
(defn main[&]
8
+
(def people {"ian" {:age "young at heart"
9
+
:nemesis "jeffrey"}
10
+
"jeffrey" {:age 7.5
11
+
:nemesis "sarah"}})
12
+
(print (enemy-of-enemy "ian" people)))