Tag Archives: map

Becoming Functional

I’ve been playing with the idea of doing some functional programming for a while now. I’ve been trying to learn and paddling around in the shallows but this week I dived right in the emacs/CIDER pool. I was aware of some dangers lurking beneath the surface: recursion, immutable data structures and the functional holy trinity of map, reduce & filter, so I came up with some ideas to face my fears. I’ve also realised my maths has got rusty so: Some of That Too.

  1. I’ve ‘done recursion’ before but I thought I’d read that my chosen weapon Clojure didn’t do tail-end recursion. This isn’t true. What it can’t do is automatic optimisation of tail-end  recursion, to stop it blowing the stack after a few thousand iterations but Clojure has a ‘recur’ expression to manually signal tail recursion and fix that. I knocked off the programme in a couple of hours and went to bed happy. My code was happily printing the first n numbers of the Fibonacci sequence but a day later I still couldn’t get it the return the numbers as a sequence.
  2. I was finding out about immutable data the hard way. You can’t build up an immutable vector, 1 element at a time. You get to keep the empty vector you created first. It’s a big mind-set change to not have variables that can vary. In my next post, I’ll try to say what I’ve learned. On this occasion it was lazy sequences.
  3. I mentioned the Algorave in my last post. I only found out about that because of an idea I had for improving my theoretical understanding of music. I realised that I could write, for example, a function that would return the 1st, 3rd and 5th notes in a major scale, using a map function.While working the theory out, I found out that Lisps are already popular in the live-coding world.
  4. At Algorave, I was inspired by the live-coded graphics to try automatically generating some graphics too, to work out the maths of mapping triangular grids onto Cartesian co-ordinates. I need that for another idea.

Three basic working programmes in about a week. They aren’t ‘finished’ but is software ever? They have delivered value via increased Clue.


A Gravitational Map of Cities

I recently made a light-hearted comment that Birmingham exerts a gravitational pull on its surrounding area. The same would be true to an even greater extent for London and that extends nationwide and beyond. This caused me to  remember reading a few months ago an economic observation that the average income of people in a city tends to increase with size because the number of paths for individuals to network and cooperate grows exponentially. This leads economists to extrapolate to a future in which most of the human population of Earth lives in densely populated mega-cities.

In contrast to this, for several years, I’ve been observing the gradual breakdown of hierarchy in companies, creative ‘industries’ and local politics (and yes, the star architecture of a city is a tree, drawn from above/below; a hierarchy. Hello, London outer-zone low-life.) Yet, the high-flying city worker’s dream is often to retire to a country cottage, away from the madness.

So why live in cities? The Internet has made it possible for us to belong to several distributed tribes, to “network” in a geography-free way, and yet… I’ve recently felt drawn by the culture of a place. I’ve joined Birmingham.io, a network of “hipsters, hackers & hustlers”, in and around Brum’s thriving ‘digital startup scene’. This netizen is feeling confused.

When I don’t know what I think, I draw pictures. When I don’t yet have an image in my head, I talk to people or get software to draw the picture for me. This time, I didn’t even know what software to use. I asked my local(ish) community if anyone knew of software that drew gravitational maps. I wasn’t sure what the question meant at the time, either: https://talk.birmingham.io/t/a-gravitational-map-of-uk-cities/1201

I think my mental image is becoming a bit clearer now: I imagine a map of the UK showing a circle for each of the n largest cities, proportional to it’s size (population / area, since the definition of city limits are fairly arbitrary. Cities will need to be broken down further, perhaps into post-codes, electoral wards or boroughs. I think employment opportunities, incomes and living costs will become relevant at a later stage, to fully explain population movement but let’s keep the model as simple as possible, for now. Represent these circles by a number, analogous to the mass of a planet or star then ‘do physics’. Clearly these celestial bodies are unusual because they have fixed relative positions but their populations feel the pull of other cities, just as the oceans of Earth experience the forces which lead to tidal movements.

How hard can it be to turn this into a software model? Maybe I’ve found an itch I can  scratch with code <cleans cobwebs off skillz>.