Functional programming without feeling stupid, part 5: Project
In the last four installments of [Functional programming without feeling stupid] I’ve slowly built up a small utility called
ucdump with [Clojure]. Experimentiing and developing with the Clojure REPL is fun, but now it’s time to give some structure to the utility. I’ll package it up as a [Leiningen] project and create a standalone JAR for executing with the Java runtime.
Creating a new project with Leiningen
You can use Leiningen to create a skeleton project quickly. In my project’s root directory, I’ll say:
Leiningen will respond with:
The result is a directory called ucdump, which contains:
For now I’m are most interested in the project file,
project.clj, which is actually a Clojure source file, and the
src directory, which is intended for the app’s actual source files.
Leiningen creates a directory called
src/ucdump and seeds it with a
core.clj file, but that’s not what actually what I want, for two reasons:
ucdumpto be a good Clojure citizen, so I’m going to put it in a namespace
My [Git repository for
ucdump] also contains the original Python version of the application, which is in <_project-root_>/python, and I want the Clojure version to live in
Functional programming without feeling stupid, part 1: The Clojure REPL
In my recent post Functional Programming Without Feeling Stupid I took a quick look at how functional programming can be a little off-putting for the non-initiated. I promised to provide some examples of my own first steps with FP, and now I would like to present some to you.
If you are thinking about getting intimate with Clojure, you will need to get to know the REPL. It is your playground, and will always be, even if you later start packaging and organizing your code.
Clojure depends on the Java Virtual Machine (JVM) and is actually distributed as a normal JAR file (Java ARchive), like most Java libraries are. You can start Clojure from the JAR, but you will save yourself some trouble and prepare for the future if you install Leiningen, the dependency management tool for Clojure. It is simple to install and run, and I will assume that you will follow the instructions on the Leiningen web site sooner or later. Now would be a good time.
When you’re done with the installation, you only need to say
to start a Clojure REPL. I’m using OS X, so what I describe here was done from Terminal. You don’t need to create a project with Leiningen if you just want to play around in the REPL.
Of course, if you don’t have Java installed, you need to get it first. Refer to the Java web site of Oracle for details as necessary. Furthermore, some of the things I will describe require Java version 7 or later.
Hearts and HipStyles
It’s Valentine’s Day, and HipStyles for iPhone is free for today only!
To celebrate and spread the love, we have reduced the price for exactly 100 per cent. This is your chance to save big!
It’s available on the App Store, so download it and tell your friends and loved ones what we already know, and you soon will: that HipStyles is the ultimate companion app for Hipstamatic users.