DEV Community

Roman Ponomarev
Roman Ponomarev

Posted on • Originally published at Medium on

Clojure: Introduction

Quick introduction to Lisp, Clojure and ClojureScript

Clojure is a dialect of the Lisp, general-purpose language with dynamic type system. It’s run on JVM and can be compiled to JavaScript (and here we are already talking about ClojureScript). Main features of Clojure (and mainly Lisp):

Best overview can be found on official site.

It would be true if I say that Clojure doesn’t have syntax. It just uses Symbolic Expressions (s-expressions): function call is a list where first item — name of the function and the rest — arguments. It’s called prefix notation or polish notation.

; clojure

(+ 1 2) ; 3
(max 13 9) ; 13

And here core concepts of clojure syntax is ended!

List is one of the most used data structure in Clojure but how we can use it as data if we use it in the code? We need treating code as data: add quote prefix (') before list or use special form quote. It’s really something like quotes in out regular texts. Of cause quotemakes sens not only for lists.

; clojure

'(1 2 3) ; (1 2 3)
(quote (+ 1 2 3)) ; (+ 1 2 3)

Greate, we have code as data — one of the most unique feature of Clojure — thanks to quote! For executing data as code you can use eval.

; clojure

(eval (quote (+ 1 2 3))) ; 6

So you can do code -> data -> new data -> code and transform your code in runtime. And it was just one example of really powerful conceptions of Clojure!

That’s enough for quick introduction to Clojure, feel free to read all links in this article for full picture. In next article we will talk deeply about syntax.

Your are always welcome to follow Medium and Twitter , ⭐️ and create issues on GitHub) , read publications on functionalhick.online . Feel free to give any feedback, I am in touch 🙌🏻


Top comments (1)

Collapse
 
wplj profile image
wplj

"In next article we will talk deeply about syntax."
Which it doesn't have, as you said.