FUNCTIONAL PROGRAMMING WITH CLOJURE FOR RAPID PROTOTYPING
There is an ongoing debate among software developers as to which programming paradigm is better: functional or object-oriented. Developing flexible programs, differ in their approaches to solving certain problems.
Functional programming is gaining popularity due to its efficiency and versatility in solving modern problems. Programs are created using sequential functions, each of which takes an input value and returns a constant output value without changing or affecting the operation of the program itself. That is why Clojure is widely used for rapid prototyping and fast delivery.
Сlojure is one of the main functional programming languages
Developed in 2005, Clojure belongs to the Lisp family of languages, which is one of the oldest groups of programming languages. Rich Hickey, the creator of Clojure, stated that he wanted to create a modern version of Lisp that could run on the Java Virtual Machine (JVM) and have the feature of parallel programming.
Clojure is a functional programming language that supports functions as first-class objects, immutable, and so-called lazy data. Clojure has access to libraries developed for the JVM due to its compatibility with that platform. This interaction allows you to call code and implement classes using Java or other JVM-compatible languages. Another feature of Clojure’s interaction with Java is that Clojure works efficiently with Java arrays. Because arrays are not collections, Clojure can create arrays, interact with their parts, convert data, etc.
The fact that data structures in Clojure are immutable simplifies the process of performing a task by a program. If we talk about multi-threaded programming, using Clojure will also be a significant advantage, since data structures can be easily “shared” between threads.
Functional Programming with Clojure. Prototyping and Delivery
Clojure has four types of mutable references. The first one is Atom, Ref, Agent, and Vars. Vars are a little bit different from all others because atoms, refs, and agents are shared memory and they share the values between threads, but Vars have their own value in each thread.
The main difference between Refs, Items, and Agents can be shown as follows. They can be synchronous and asynchronous, and they can be coordinated and autonomous. So, Ref is synchronous and coordinated. Atoms are synchronous and autonomous, and agents are asynchronous and autonomous. Autonomous is independent and synchronous will wait for things to be done. Asynchronous will immediately continue to perform the next part of the program and run it in the background.
It is short for the Read-eval-print loop. It is a program that said, “Read an input”, then “Evaluate an input” and “Print the result”. These three functions are running in a row. It was first introduced in LISP and now we have REPL kinds of things in many different programming languages, but in Clojure, it’s a better version.