Skip to content

Commit cbbff58

Browse files
author
Raphaël Squelbut
committed
add exercices 24 / 25 / 26
1 parent b51408e commit cbbff58

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/structured_data.clj

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
(or (apply <= a-seq) (apply >= a-seq)))
8888

8989
(defn toggle [a-set elem]
90-
(if (contains? a-set elem )
90+
(if (contains? a-set elem)
9191
(disj a-set elem)
9292
(conj a-set elem)))
9393

@@ -103,13 +103,16 @@
103103
(contains? (:authors book) author))
104104

105105
(defn authors [books]
106-
:-)
106+
(set (apply concat (map :authors books))))
107107

108108
(defn all-author-names [books]
109-
:-)
109+
(set (map :name (authors books))))
110110

111111
(defn author->string [author]
112-
:-)
112+
(let [life-info
113+
(fn [author] (if (or (:birth-year author) (:death-year author))
114+
(str " (" (:birth-year author) " - " (:death-year author) ")")))]
115+
(apply str (:name author) (life-info author))))
113116

114117
(defn authors->string [authors]
115118
:-)
@@ -137,4 +140,17 @@
137140

138141
; %________%
139142
(comment
140-
(print "coucou"))
143+
(def china {:name "China Miéville", :birth-year 1972})
144+
(def octavia {:name "Octavia E. Butler"
145+
:birth-year 1947
146+
:death-year 2006})
147+
(def friedman {:name "Daniel Friedman" :birth-year 1944})
148+
(def felleisen {:name "Matthias Felleisen"})
149+
150+
(def cities {:title "The City and the City" :authors #{china}})
151+
(def wild-seed {:title "Wild Seed", :authors #{octavia}})
152+
(def embassytown {:title "Embassytown", :authors #{china}})
153+
(def little-schemer {:title "The Little Schemer"
154+
:authors #{friedman, felleisen}})
155+
156+
(def books [cities, wild-seed, embassytown, little-schemer]))

0 commit comments

Comments
 (0)