Today I will be looking at exception handling. Clojure provides the normal try-catch-finally block to catch exceptions and has the following general syntax
Ahmed on IT
A techno trekkers journal of software development and other meanderings
Tuesday, September 15, 2020
#100DaysOfClojure (Day [14] flow-control-cont-3)
Monday, September 14, 2020
#100DaysOfClojure (Day [13] flow-control-cont-2)
My apologies, as fun as Clojure is, I managed to drag myself away and took a 2 day break. Today I will look at recursion in Clojure. First let's I will look at recursion as used in most non functional languages where the function is called within the function(the function calls itself). But this usually only works up to the size of the stack frame. Lets look at a factorial function as a recursive example (The N at the end of the number just lets Clojure REPL know that it is a Clojure BigInt)
Friday, September 11, 2020
#100DaysOfClojure (Day [12] flow-control-cont)
(println “Bye 4 Now!”)
Thursday, September 10, 2020
#100DaysOfClojure (Day [11] flow-control)
In Clojure everything is an expression because everything returns a value. Even a block of multiple expressions will return the last value. There are 3 basic flow operators: if, when and do, which themselves are also expressions.
Wednesday, September 09, 2020
#100DaysOfClojure (Day [10] Sets)
A Set is a collection with unique elements. They are like mathematical sets, unordered and unique. They are used for checking whether a collection contains an element or removing an arbitrary element. You will notice they can contain any type including functions.
Tuesday, September 08, 2020
#100DaysOfClojure (Day [9] Maps)
Today I will look at Maps, one of the most important collection types in Clojure. Maps are collections of key-value pairs. Keys can be of any type in Clojure including functions, lists, other maps etc. The are 3 types of maps in Clojure: Hash Maps, Sorted Maps and Array Maps. Sorted maps keep the key value pairs in a certain order which implies that a lookup time may not be constant and it also allows you to traverse the values in the order of the keys. Sorted maps have a constraint in that the keys have to be comparable.
Monday, September 07, 2020
#100DaysOfClojure (Day [8] Vectors)
Vector is another collection data structure that allow random access and add new elements to the end of the collection.
Sunday, September 06, 2020
#100DaysOfClojure (Day [7] (lists))
The Clojure programming language is designed around data processing which includes the code as data. Today I get into the very foundations of programs in Clojure, the collection data structures. Remember that data in Clojure is immutable so in order for Collections to be efficient they need to be persistent, which means that all the copies have to share the common data. The are 4 collection types, Lists, Vectors, Maps and Sets. And these collections share a set of core functions :
- conj - returns a new list with the new add item added
- seq - returns sequence to of the collection
- count - return the number of items in a collection
- empty - returns an empty collection of the same type
- = - determine the value equality of one or more collections
Saturday, September 05, 2020
#100DaysOfClojure (Day [6] Functions Continued)
Today I am continuing with 3 more useful function concepts: How to define functions, anonymous functions and using apply with functions
Friday, September 04, 2020
#100DaysOfClojure (Day [5] Functions)
The excitement is building up, today I played with functions. A Clojure function has the following structure
Thursday, September 03, 2020
#100DaysOfClojure (Day [4] Basics)
Today I can dip my toes into the language itself. I will be looking at the some of the syntax and forms, Clojure refers to valid code as forms. Clojure has literals which consist of primitive data types, symbols and collections.
Wednesday, September 02, 2020
#100DaysOfClojure (Day [3] IntelliJ + Cursive)
With the wide variety of editors/ides available, it was a difficult decision to make. So how did I make this decision you ask? I made the decision based on the quality of the documentation and my familiarity with the editor. Hence I chose IntelliJ and the Cursive plugin. Cursive provide 3 licenses, personal, commercial and non-commercial. Since I am only using it to learn Clojure, I chose the non-commercial licence which is a free 6 month renewable licence.
Tuesday, September 01, 2020
#100DaysOfClojure : (+ Day [2] Tools)
Today was a busy and tiring day, so I decided to keep it light and explore the tools available for Clojure. The first tool of importance is Leiningen. It is a build automation and dependency management tool for the Clojure programming language written in Clojure itself. It integrates well with Maven repositories and the Clojars repository for Clojure libraries. On an Apple Mac you can install Leiningen very easily using homebrew.
- The ability to create projects
- Compile and package projects
- Run projects
- Run tests
- And more….
- Emacs with Cider plugin
- Atom with nrepl
- Cursive plugin for IntelliJ
- Nightcode
- Counterclockwise a plugin for Eclipse
- Vim with plugins
- Light table
- SublimeText with SublimeREPL
- Netbeans Clojure
- VS Code with Calva plugin