Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
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
- 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-products 2 (for [cart carts] (get-product (:product-id cart)))]3 4 (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!
4 tips to help you understand clojure was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.