Its been more than one month since I attended the “Introduction to Clojure” talk by Baishampayan Ghose (@ghoseb on twitter) as part of the Java Pune Meetup group’s monthly meetup. I had scribbled down some notes, that I promised to blog about, but other things just cannibalized my blogging time.
Anyway, better late than never, here are some of excerpts and salient features of clojure as described by “BG”.
- Clojure is a variation of LISP, but is a JVM based language so gives interoperability with the JVM.
- One can do functional programming with Clojure.
- One of the interesting things about clojure is that you can bring the domain of your problem statement into this language, rather trying to adapt Clojure to the domain.
- Clojure has profound state management capability.
- Protips for Clojure, an LISP based language for that matter
- 1) Everything, i.e every statement in LISP is perceived as a list of items.
- 2) the first item in the list, is always considered to be a function.
- As a consequence of the above, all LISP statement are read as “prefix expressions”.
- Few interesting mentions about Datatypes in Clojure ->
- 1) basic datatypes in Clojure start at Long and Double as against int and float for those from the C,C++,Java world
- 2) there exists a dedicated datatype called “Ratio” that enables much higher levels of accuracy in computation when dealing with real numbers such as ‘Pi”(22/7)
- 3)RegularExpression is a one of the built in datatypes
- 4)There is also a datatype called ‘Keyword’
- Some default datastructures built into Clojure ->
- 1)List – its a singly linked list that grows from the front
- 2)Vector – its a collection of values indexed by contiguous integers that grows from the end.
- 3)Map – its a standard key,value pair datastructure
- 4)Sets – its a collection unique values (yes the same way we refer to sets in maths)
- One key thing about Clojure is that all datastructures are immutable and when you code with them, you only perform transformations over them and copy them over to newer items while playing around with them
- The other interesting aspect of this Clojure 101 talk was about sequences – where you can specify the first item of a sequence followed by instructions to recursively generate the next next elements of the sequence.
- Namespaces are part of the language. You can create and switch in between namespaces even while you are playing around in the commandline.
- And namespaces can be imported around as if they were packaged libraries.
These are the major things that BG spoke about. As BG mentioned at the beginning of the talk, the goal of the above points is to give Clojure aspirers a good springboard, from where they can easily jump into the world of Clojure programming.
Hope this helps someone looking for a headstart in Clojure.