Automate the boring stuff with Babashka
Clojure Programming Basics
Babashka Basics
Programs, Scripts, Pods, and Libs Babashka can be launched for interactive programming (REPL)
bb --nrepl-server bb --socket-server
Data Structures
int, double Vectors, Lists, Sets and Maps(Dictionaries) Strings, RegExp
Flow Control
if(When), While
Map, Reduce
doseq, dotimes
(doseq [n (range 5)]
(println (str "Line " n)))
repeat, iterate, cycle
(take 5 (repeat "Hello"))
(zipmap [:score :hits :friends :level :energy :boost] (repeat 0))
;; repeatedly to generate a sequence of vals
(take 10 (repeatedly (partial rand-int 100)))
Iterate
;; simple
(take 3 (iterate inc 5))
;; slightly complex
(defn savings [principal yearly-rate]
(let [monthly-rate (+ 1 (/ yearly-rate 12))]
(iterate (fn [p] (* p monthly-rate)) principal)))
(take 13 (savings 1000 0.01))
(take 5 (cycle ["a" "b"]))