Things Ian Says
functional programming
Here are all the items relating to functional programming (page 1 of 1)
Breadth First Graph Traversal in Clojure (Kiwiland Example)
Saturday, 11 May 2019
In my previous article, I looked at how to create a graph in Clojure, and find the length of various journeys within it. I will now move on to look at how to search the graph, to solve some of the other questions in the Kiwiland Trains Programming Challenge. This will focus primarily on the implementation of a breadth first search.
Building a Graph in Clojure, for the Kiwiland Railway
Tuesday, 9 April 2019
I was recently looking at a programming test, where the challenge is to represent a railway system (called “Kiwiland”) and then deduce various facts about it (for example the distance for a certain route). I wanted to develop this in Clojure, and thought it would be an interesting thing to work through on my blog.
Kiwiland Railway Problem Statement
Tuesday, 9 April 2019
This is a statement of the problem I am working through in the following articles: Building a Graph in Clojure Breadth First Graph Traversal in Clojure Note that this is taken from github.com/coop/kiwiland. Problem Statement The local commuter railroad services a number of towns in Kiwiland. Because of monetary concerns, all of the tracks are ‘one-way’. That is, a route from Kaitaia to Invercargill does not imply the existence of a route from Invercargill to Kaitaia.
Memoization
Monday, 14 September 2015
Some of my recent blog entries have dealt with using functional practices in Javascript. There are obviously downsides to functional programming as well, and one commonly stated one is around performance.
One area this applies to is in the large number of function calls resulting from this approach — particularly when we are writing recursive code.
We will give an example of this problem — calculating Fibonacci numbers — and then look at a technique known as memoization as a way of improving performance.
Functional Example
Saturday, 12 September 2015
This blog entry will take the techniques discussed in the previous articles about functional Javascript and currying and apply them to an example problem.
Curried Javascript
Tuesday, 8 September 2015
In my previous blog entry, we looked at how functions are first class entities in Javascript, what an anonymous (or lambda) function is, and how we create and use closures.
We will now look at another functional technique, known as currying, which builds on those concepts.
Functional Javascript
Thursday, 3 September 2015
Functional programming is seeing an increase in popularity, as can be seen in rising adoption of languages like Scala, Clojure and Erlang. Even Java has introduced lambdas (more about lambdas, later).
Javascript supports a functional programming style and I find that working within that style makes many things simpler when developing Javascript. This is particularly true when working with promises.
This blog entry discusses some basic functional techniques and demonstrates how they can be used within Javascript. It should be useful to both people who wish to adopt a more functional style in their Javascript, and to people who just want to understand more about functional programming.
Promises in Javascript
Wednesday, 10 June 2015
Javascript is single threaded and non-blocking, which means that lines of Javascript code are not necessarily executed in the same order they are written. This can cause problems with asynchronous behaviour, for example if the Javascript needs to call two different APIs in a specific order. This article discusses this challenge, and looks at the use of promises to address them.