Clojure intermediate workshop
Setup Instructions
Just do the following one by one, and you should be fine.
Java 8
You will need Java to work with this Clojure workshop content.
First, make sure you have Java 8.
- Run
java -version
in your terminal. - If Java is not installed, please download and install Java 8 from here.
- Once you are done,
java -version
should show you a Java 1.8.x version.
Notes:
- If you have Java 9+, that should be OK too.
- The LightTable editor is known to break with Java 9. Use Java 8 if you are keen on using LightTable.
- We have not tested this project with Java 7 and earlier.
Leiningen
Follow Leiningen setup instructions here.
Fire up a REPL
- Clone this project
- Open your terminal, and do the following.
cd
into this project's root directory- Use
lein repl
command to start a REPL with Leiningen. - Wait for it... the REPL will start and print out a message with some useful information
- Locate the
port
andhost
information in the message. We will need this information soon.
Note:
- Boot should be fine too, but you may need to generate your own boot file(s).
Code Editor and Tooling
Set up an editor and figure out how to evaluate Clojure code with it. We are fine with you choosing the editor as long as your editor can do,
- Connect to a Clojure REPL from the editor
- Evaluate snippets and/or entire namespaces in the connected REPL from the editor.
- Code navigation
- Paredit / Parinfer
Editors we can help out with
- Emacs
- Vim
- Cursive
Cursive (IntelliJ)
If you don't have an editor setup, we suggest you use Cursive with IntelliJ. Please follow instructions from here. Do note that you may need to use it in trial mode or get an appropriate license ahead of time. There's a cost-free license available for personal/non-commercial hacking.
Further reading
Inspiring and insightful source code
Clojure Core
This one is not a surprise, but reading sources in the core Clojure library (with the clojure.core namespace being a good starting point) is highly recommended. This one comes directly from the masters, and it can not get more idiomatic (and simpler, really) than this.
Monger
Monger uses official Java client for talking with Mongo. This is a standard way of writing database wrappers. Few interesting parts,
- monger.query/exec uses doto to run a bunch of Java methods
- monger.query/exec also uses Protocols monger.conversion/ConvertToDBObject and monger.conversion/ConvertFromDBObject to convert objects at boundary. Monger converts mutable data List/DBList to Clojure vectors.
Carmine
Carmine is Redis client and is written almost from scratch.
- API is built with a macro
- An atom is used to collect test results
- Exercise - Can we use core.async here to remove dependency on Thread/sleep?
- It uses IConnectionPool to create different implementations of connection pool
- It uses a edn file to map list of commands Redis supports to Carmine API functions using defcommands macro
core.cache
core.cache is Clojure contrib library. It provides in-memory implementations of different caching strategies
- core.cache/defcache is a macro that reduces repetition of defining a type
- This shows that mutation to cache creates a new value
clucy
This one is old, but it really stands out for a few reasons as far as learning goes
- A concise example that shows Java inter-op
- Careful design considerations, and thus what a succinct piece of code within a single namespace can achieve
- Clever use of
meta
attributes onvars
Durable Queue
This one pushes some limits on Clojure-Java interop without descending down into Java (language) land. An instructive piece of source, all within a single namespace.
Links
Copyright and License
Copyright � 2018-2019 IN/Clojure.
Distributed under the MIT license.