Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clojure is difficult, but worth it.

Avatar for Sezal Jain Sezal Jain
February 15, 2020

Clojure is difficult, but worth it.

Avatar for Sezal Jain

Sezal Jain

February 15, 2020

Other Decks in Programming

Transcript

  1. /11 2 • Parentheses • Debugging • For • Lazy

    Sequences • Lack of Examples • Interaction with db • Hon’ mention Outline
  2. Parentheses • Cursive (IntelliJ), Cider(Emacs) • Structural Editing • Paredit

    • Slurp, barf Links http://danmidwood.com/content/2014/11/21/animated-paredit.html https://cursive-ide.com/userguide/paredit.html (- 1 (* c (+ a b) d) /11 3
  3. • Repl is great. Use it! • Print debugging •

    hashp, log/spy • Cider Tracing, Debugger Links: https://eli.thegreenplace.net/2017/notes-on-debugging-clojure-code/ https://docs.cider.mx/cider/debugging/tracing.html Debugging (let [x 10 y 10] (if (= x y) (prn (func1 x y)) (func2 x y))) (-> [1 2 3] (map inc) (prn) (filter even?)) /11 4 (defn debug [x] (prn x) x)
  4. • Repl is great. Use it! • Print debugging •

    hashp, log/spy • Cider Tracing, Debugger Links: https://eli.thegreenplace.net/2017/notes-on-debugging-clojure-code/ https://docs.cider.mx/cider/debugging/tracing.html Debugging (let [x 10 y 10] (if (= x y) (debug (func1 x y)) (func2 x y))) (-> [1 2 3] (map inc) (debug) (filter even?)) /11 5 (defn debug [x] (prn x) x)
  5. • It’s a list comprehension • {2x | x ∈

    [1 2 3 4], x2>3} • map/filter • doseq • loop/recur/reduce • multiple sequences/dimensions for /11 6
  6. Lazy Sequences (do (map prn [0 1 2 3 4

    5 6 7 8 9 10]) (println "Hello, world!”)) “Hello, world!” (defn slow-fn [a] (Thread/sleep 1000) (+ 1 a)) (time (slow-fn 5)) "Elapsed time: 1004.547512 msecs” (time (map #(slow-fn %) [1 2 3]) "Elapsed time: 0.116936 msecs" Be Aware!! • Lazy — for, map, filter, range • Not lazy — doall, doseq, reduce Be Aware!! /11 7
  7. Lack of Examples [clojure] - 16068 • Clojurians slack, ask.clojure.org,

    clojure reddit • Dig into library source code • Write blogs • Ask/answer questions Severe lack of open source code [python] - 1,345,241 [ruby] 211,001 [haskell] 43,115 /11 8
  8. Write migration function using ragtime etc Migrate Write crud functions

    for the table using jdbc Magic vs No Magic Write a Model for a new table Write sql migration for a table, add constraints etc Migrate Django Clojure Migrations are auto-created, Migrate /11 9
  9. Sql knowledge a must Minimal knowledge of sql Write a

    Model for a new table Write sql migration for a table, add constraints etc Write migration function using ragtime etc Migrate Write crud functions for the table using JDBC Migrations are auto-created, Migrate /11 10 Magic vs No Magic