Clojure is a dialect of the Lisp programming language that has long been known by the free software community, but Clojure runs on the Java Virtual Machine JVM, and has conquered corporate environments precisely by maintaining compatibility with JAVA and being a pure language functional.
I’ve already studied and worked with various programming languages, but what struck me the most in Clojure is its almost alien syntax, I remembered the movie the Predator, great.
Clojure is an alien dialect
I used FreeBSD to make this article, so to install Clojure on FreeBSD simply type in the terminal the commands:
In the above command we installed Clojure and Leiningen to automate projects.
Open another terminal session and enter the command lein repl:
Ok, now it’s possible for you to type the code in clojure and see the results.
All interaction with clojure starts with parentheses (…), as we can see we did a classic Hello World using the function println and it returns nil equivalent to a void or null.
1.2 Creating Functions
To create functions we use defn:
If you wanted to multiply for example, just use the * operator or to divide /.
You can use the TAB to fill in commands automatically. Another example, looking for the intersection of the two vectors:
1.3 Using reduce, map, filter
1.4 More advanced Lazy Seqs
Let’s create a fictional alien database:
Let’s see how long it takes to execute the function below:
Creating a range:
Clojure is a very cool language to work on, at least it was my first impression, predicting to do other more advanced language tutorials, possibly using clojure for data analysis.