What Will I Learn?
- Whats the Clojure ?
- Why Clojure
- How to install Clojure
- How to create a simple application
Requirements
- A PC/laptop with any Operating system such as Linux, Mac OSX, Windows OS
Difficulty
- Basic
Tutorial Contents
Why Clojure?
First of all, it's one of the last members of the Lisp family. In other words, Lisp is a brand new language with many experiences gained in the long history. It was created by Rich Hickey in 2007. However, despite such a short period of time, there are libraries and user groups at a sufficient level. What is interesting is that this language, which does not even mention a long name, has started to make a lot of noise in the last few years. It has taken itself to a different dimension with the passing of big companies.
Clojure is not interpreted like other script languages. The written codes are compiled into a Java byte code to work on the JVM. On this count, the suspects on speed are removed from the center. Another important feature of working on the JVM is that it can directly access all the libraries that Java has and use them as you wish. You can add Java codes to the Clojure code that you write on this page as well as write some of your Java code with Clojure. I especially know that the key points of large Java applications are programmed with Clojure.
It's a fully functional language. It has all the capabilities of functional programming as it does in other Lisp languages. In other language paradigms, you can write the codes that make it hard to write, just like an English writer. As you enter, you become more in love with. Laziness in infinitely long sequences improves thinking in many ways. It gives a distinct impetus to mathematical problems and scientific projects.
As you can see from the picture, the computers continue to accelerate. Of course this goes as far as one. Now, the speed of computers affects whether they are multi-core or not. At the same time, programs that operate on many cores have large pre-requisites. So functional programming is a blessing for concurrent work. Other competitors for this job at Clojure are Scala, Go, and Erlang. The information on these languages is constantly increasing. And surely it will continue to increase. Especially nobody can deny the rise of Go in the last days after Scala's hard entry. In Clojure, he enters these tongues, taking in the backings of Java and Lisp. And it's a perfect fit for this kind of work. There is even a Clojure Course on this topic. Interested people can take care of it.
Clojure is really fast as other functional programming languages. Because the underlying data structures can not be changed (immutable). So when you are creating a list and you're working on it, the last thing you hear is the same as the first one. Especially if you do not want to change (side effects) you can not make permanent changes to all data structures. You can not get a copy of a listing somewhere in the code. This feature, which is very interesting to me at first, is really very useful. Can you say everything without changing it? Yeah. In general, this is how you can handle every business. However, when it is necessary, Clojure permits you to make changes. There's no point in using it unless you need it.
A little Syntax
As I said in Clojure, Lisp is one of the family tongues. It uses the same syntax structure as it does in other Lisp languages. Although this structure seems to be difficult at first, it is actually more elegant and readable than all other languages. I realized at first that every parenthesis there was actually a goal when I thought of what I needed to do. It is not as complicated and incomprehensible as it is said.
We need to have a good development environment ready for the brackets. The best development environment for Lisp is definitely Emacs. There is even a separate Lisp dialect written for himself. Besides Emacs, Eclipse, Netbeans, or IntelliJ can easily write their code here. I write Clojure codes in Vim for being a Vim fan. And I am happily happy. I set up everything I needed and set it up comfortably. I will be going to talk about this soon (I could not get me into it if I tried to get used to Emacs.) I could not get the elegance and simplicity in Vim, Emacs fanatics would be regressed but unfortunately it is still VIM!
Installation
To start writing code with Clojure, download the java file from the download page and open it with the command below.
java -jar clojure-1.5.1.jar
On this page, there will be a Read Evolution Print Loop (REPL) environment. You can now do your first experiment here (if you install the Clojure REPL named application in the android market, you can have the same atmosphere)
user=> (+ 5 6)
11
What the code above does is clear. For now, just look at it. We have not yet set up the necessary environments.
Package Manager
Clojure has a nice package manager as well as having many other languages as well. With this manager, you can create and run a new project. Ubuntu / Debian users can have this nice manager by installing the following package.
sudo apt-get install leiningen
After the installation is over, we can create a new project by going to a directory we want.
lein new hello
If you have not encountered any difficulties, you should see something like the following. If you encounter an error (I had trouble with some packages, I installed it by issuing a warning from normal, and you should not encounter a problem under normal conditions).
Created new project in: /home/fztbyt/hello
Look over project.clj and start coding in hello/core.clj
You can start coding by entering hello / core.clj as in the same warning. Of course, you also need to set your environment before going to the encoding. Light Table IDE Clojure named provides a nice environment to encode. If you are not a fan of Vim or Emacs and you are complaining about the cumbersome environments like Netbeans, Eclipse, I'd take a look. Sublime Text is an alternative to this job.
hello
├── project.clj
├── README
├── src
│ └── hello
│ └── core.clj
└── test
└── hello
└── test
└── core.clj
The project that Lein created for us is like the one above. We will write our code into src / hello / core.clj. When we want to use our codes, we can enter interactive sales using lein repl. Or you can use the lean run command to run it when you write the web application.
We define the project dependencies we wrote in project.clj and use lein deps for the necessary operations. We can install the necessary packages without experiencing any problems. You can also use the lean test for the tests we wrote in the same way.
Let's do our first simple application without really knowing what it is now. First, open src / hello / core.clj and add the following code.
(defn say-hello [x]
(println "Heyy " x " !"))
Later in the REPL environment with lein repl. In the pre-emptive section, first let us specify what code to use with (use 'hello.core). And then, in this code, let's call the function named "hello" (we do not know how it works now) with the "Clojure" argument.
REPL started; server listening on localhost port 40061
user=> (use 'hello.core)
nil
user=> (say-hello "Clojure")
Heyy Clojure !
nil
user=>
We have done the simplest and unnecessary application :)
Curriculum
Unfortunately I could not find any curriculum
Posted on Utopian.io - Rewarding Open Source Contributors