Hello World! In Clojure

So, as part of my new year’s resolution for 2018 I decided to learn some functional programming, and I picked the clojure language to be my tool.

I’ll just use this space to write down the things I’m doing during my learning.

Of course the first exercise in every new programming language is to write a hello world, so I started by reading clojure’s getting started to learn how to begin.

Because clojure is a JVM language make sure you have java installed at you OS before starting.

While reading the getting started to understand how to install clojure I discovered there is a very nice build tool called Leiningen, which is pretty easy to install, you just have to download a script to one of your binaries path, like:

$ mkdir $HOME/bin
$ cd $HOME/bin
$ wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
$ chmod +x lein


After having leiningen installed it becomes pretty easy to have your first hello-world in clojure up and running:

$ lein new app hello-world

This command will bootstrap a project with everything set to have a hello-world running and the directory tree will look like:

├── doc
│   └── intro.md
├── project.clj
├── README.md
├── resources
├── src
│   └── hello_world
│       └── core.clj
├── target
│   └── default
│       ├── classes
│       │   └── META-INF
│       │       └── maven
│       │           └── hello-world
│       │               └── hello-world
│       │                   └── pom.properties
│       └── stale
│           └── leiningen.core.classpath.extract-native-dependencies
└── test
    └── hello_world
        └── core_test.clj

The contents of src/hello_world/core.clj will have something like:

(ns hello-world.core

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

To run it you enter the project directory and tell lein to run:

$ cd hello-world
$ lein run

And the output you already know what it is!

See you at the next post!