paint-brush
4 tips to help you understand clojureby@luklukluhuringsantoso
543 reads
543 reads

4 tips to help you understand clojure

by Lukluk Luhuring SantosoApril 13th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<strong>Clojure is</strong> a dynamic, general-purpose <a href="https://hackernoon.com/tagged/programming" target="_blank">programming</a> language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - 4 tips to help you understand clojure
Lukluk Luhuring Santoso HackerNoon profile picture

Clojure is a dynamic, general-purpose programming language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.

Clojure is functional programming, all is function you can see the basic pattren :


(fn param-1..param-n)(fn (fn-1 (fn-2 param-2–1) param-1–1))

Stop pulling your hair out while understanding existing Clojure project, here four tips that I can share with you while right now I also still suffering understanding Clojure code

  1. Reading function by function starts from the last child function to the first parent

so value from get-user-profile will be collected by for and store to :data , than protobuf will build user-batch, then publish-topic from protobuf value

this technique will be pain less then read from the first parent then go to the last child

2. Reading nested hash map also start from the last child of key

How to get follower of his facebook account:

  • Java

Object.getData().getProfile().getSocialMedia().get(0).getFollower()

  • Clojure

(:follower (first (:social-media (:profile (:data object)))))

3. Use lein repl if you stuck something

you may know debuging clojure on itellijIDEA is worst, not fully make you happier, for example





1 (let [atc-products2 (for [cart carts] (get-product (:product-id cart)))]34 (response **atc-products**)5 (println "HERE PRODUCTS" atc-products))

console>> HERE PRODUCTS ({:product-id 123 :product-name "Sepatu"} {:product-id 456 :product-name "Sandal"})

Let say i put a breakpoint at line 4, you will be wondering in debugger panel atc-products will be shown as null, but you will see some values of atc-products in the console after println.

with lein repl you can execute parentheses by parentheses, or even function by function if you got an error you can fix instantly and then just add :reload

(require #[namespace :as alias] :reload)

4. Use rainbow parentheses plugin

help your eye catch ton of parentheses in clojure


https://github.com/johngeorgewright/atom-rainbowwith atom

apm install johngeorgewright/atom-rainbow

Thanks!