A concept of polymorphism in Clojure
Working with larger Clojure projects or libraries requires us to use some concepts that we all know from the Object Oriented Programming (OOP) world.
Recent content on Ostash.Dev
Working with larger Clojure projects or libraries requires us to use some concepts that we all know from the Object Oriented Programming (OOP) world.
As programmers we work with data every day. It has different forms: data may come from the database, an API endpoint or from the user input.
Although in Clojure we strictly adhere to the idea of immutability we still have an option to work with mutable data structures.
Today we will discuss a topic of pre and post assertions (conditions) in Clojure. The language gives programmers an option to set certain conditions we want to constrain our function with.
Homoiconicity (code as a data structure) is one of the pillars of the Clojure language. It gives the extensibility and flexibility to the language.
Conceptually metadata is an ability for the symbol or the collection to have some additional information for the Clojure compiler. It is implemented as a map data structure and is often used to convey the type information to the compiler, documentation and compilation warnings.
All data structures in Clojure are immutable. Any changes we do will result in a new data structure leaving an original one untouched.
Destructuring in Clojure can be confusing for someone coming from the language where this technique is not implemented. Hopefully when you are done reading this article, destructuring will make sense and you will be implementing this method in your own coding projects.
Today we are going to talk about ClojureScript and review many useful functions and concepts you need to know when working with Clojure/JavaScript interoperability.
Clojure comes with many useful functions that are a great learning resource for those who are just starting to explore the language.
If we would like to comment out a line of the code we simply use a semicolon at the beginning. To comment out a block of the code we use hash underscore #_ (reader macro).
Let’s talk about namespaces today. Below is a structure of the core.clj file that is located in /src/app/ directory. Function ns sets the namespace.
In Clojure we can bind a piece of the code/data to a var (variable). To declare a global var we use a def special form (similar to let keyword in JS world).
Functions in Clojure are data structures since the language follows code as a data structure principle (homoiconicity). In Clojure those data structures are lists since it is a dialect of the LISP (LISt Processor) language, the second oldest language still in use today.
Mutable data structure can be changed after creation immutable cannot. Paradoxically, when you need to mutate a data structure, is a time then you should use an immutable data structure because it allows a structured mutation.
I’m Roman Ostash, a self-taught Software Developer. I love to code and to build applications. Thinking outside of the box, problem solving skills and perseverance in achieving my goals are helping me in my personal and professional development.
Mutating a value. When you receive a data structure that is in its identity mutable, like an array or object, the best thing to do is to always assume that it is a read-only data structure and that you are not allowed to mutate it.
What is a higher order function(HOF)? If a function receives as its input one or more functions or/and returns the function we can called it HOF.
Currying is an act of taking one function that receives more than one argument and refactoring it so it becomes HOF(a higher order function) that returns series of functions each accepting only one argument and only evaluating once we receive our final argument.
Before we explain what arity is, let’s make a clear distinction between parameters and arguments in a function. The parameter is a variable declared in the function expression.
What is a function? For the function to be a function it has to return something, otherwise is a procedure. Function is a semantic relationship between input and computed output.
Like many of developers that were coding for the last few years, I was following mostly object oriented programming paradigm. Let’s not go into details on its specific implementation (hopefully the reader is familiar with it.