What is Clojure?

The podcast "Rich Hickey on Clojure" explains what made Rich Hickey consider the idea of creating a new programming language called Clojure, based on Lisp and running in the Java Virtual Machine.
What I enjoyed the most of the podcast was the explanation of the immutable data structures because if you consider data to be immutable and consider a big program then you should worry for memory as everything would be kept in memory and this is not efficient. So, what makes Clojure efficient? It turns out the programming language uses Single Linked List and instead of creating an exact copy of an Array or Set but with a value change, it uses the Nodes of the Linked List just to add the new path of the changes. In other words, if A->B->C and you change B to D it create a new A to point D and D will point C, so you would have your two lists A->B->C and A'->D->C. This intelligent approach reduces redundancy and memory usage by recycling the parts of the structures that could be recycled.

It is really interesting to understand that this easy solution can solve many of the problems that arise from immutable data. On the other hand, this approach also reduces the time it takes to create data structures and it makes that the changes on the data can take around the same time in Clojure than in any other programming language. As an example, changing a number on a integer array would take O(1) in almost all programming languages, if we used the normal immutable data approach it would take O(n) n being the size of the array, instead in Clojure it takes O(1) because it only needs to copy a part of the data structure and not the complete one.

Comentarios

Entradas más populares de este blog

Two is more than double of one

What makes Lisp Lisp?

Is really functional programming better?