Creating a new project
- 
lein new app my-app
 
Test
https://github.com/jakemcc/lein-test-refresh
- 
lein test-refresh
 
Test using spies to check for side affects
https://engineering.fundingcircle.com/blog/2016/01/11/tdd-in-clojure/
- 
(deftest crappy-function
 - 
(let [calls (atom [])]
 - 
(with-redefs [some-namespace/some-function (fn [arg] (swap! calls conj arg) "I am really crappy")]
 - 
(is (= "I am really crappy" (crappy-function mock-function 3 5)))
 - 
(is (= @calls [{:a-key 3 :another-key 5}]))
 - 
)
 - 
)
 - 
)
 
Lein Try
https://til.hashrocket.com/posts/3081d5943b-try-a-clojure-project-in-th…
add plugin to ~/.lein/profiles.clj
My file is:
- 
{:user {:plugins [[lein-try "0.4.3"]]}}
 
type lein try PLUGIN
e.g.
- 
lein try seesaw
 
seesaw list events
Run the repl in a seesaw project
- 
(use 'seesaw.dev)
 - 
(show-events (combobox))
 
Memorize example
- 
(ns try.core
 - 
(:gen-class)
 - 
(:require [clojure.string :as str] )
 - 
)
 - 
 - 
 - 
(def stringA "all abc")
 - 
(def stringB "sadsdadsa abc")
 - 
(def stringC "@p1 abc")
 - 
(def stringD "@p2 abc")
 - 
 - 
(defn remove-particular-start-DONOTUSE
 - 
[input-string prefix-to-remove]
 - 
(do
 - 
(println (str "CALL function:" input-string ":" prefix-to-remove))
 - 
(if (str/starts-with? (str/lower-case input-string) (str/lower-case (str prefix-to-remove " ")))
 - 
(subs input-string (+ 1 (count prefix-to-remove)))
 - 
input-string
 - 
)
 - 
)
 - 
)
 - 
(def remove-particular-start
 - 
(memoize remove-particular-start-DONOTUSE)
 - 
; remove-particular-start-DONOTUSE
 - 
)
 - 
 - 
(defn -main
 - 
"I don't do a whole lot ... yet."
 - 
[& args]
 - 
(do
 - 
(println "Start of app")
 - 
(println (remove-particular-start stringA "all"))
 - 
(println (remove-particular-start stringB "all"))
 - 
(println (remove-particular-start stringC "all"))
 - 
(println (remove-particular-start stringD "all"))
 - 
(println (remove-particular-start stringA "p1"))
 - 
(println (remove-particular-start stringB "p1"))
 - 
(println (remove-particular-start stringC "p1"))
 - 
(println (remove-particular-start stringD "p1"))
 - 
(println "SECOND CALL")
 - 
(println (remove-particular-start stringA "all"))
 - 
(println (remove-particular-start stringB "all"))
 - 
(println (remove-particular-start stringC "all"))
 - 
(println (remove-particular-start stringD "all"))
 - 
(println (remove-particular-start stringA "p1"))
 - 
(println (remove-particular-start stringB "p1"))
 - 
(println (remove-particular-start stringC "p1"))
 - 
(println (remove-particular-start stringD "p1"))
 - 
(println "End of app")
 - 
)
 - 
) ;end of main function
 
RJM Article Type
              Quick Reference