All posts by Bill

F Natural is Back

After a long hiatus I started teaching myself Python, and as a warm-up I wrote a little lambda interpreter in it. I was blown away by how convenient and quick it was in Python, and the project has kind of snowballed to the point where I have most of my previously only vapourware “F♮” functional language up and running (albeit only under a test harness.)

The source is GPL and on GitHub:  https://github.com/billhails/PyScheme

Singletons are NOT an anti-pattern

I get annoyed sometimes when beautiful patterns like the Null Object Pattern get dismissed out of hand because they use singletons. There is nothing wrong with singletons in themselves, the problem, and the anti-pattern, is when people use singletons to store global state. A good singleton, like the Null Object, keeps no (mutable) state and as such behaves as a constant, not a variable.

A Story I Have to Tell

… because it’s true, and because it’s funny, or at least with forty years of perspective parts of it seem funny, it didn’t seem very funny at the time …

As kids growing up in the North East of England in the seventies,  we were the original vinyl generation. Music was our life. Not just any music though, we were very disdainful of Top of the Pops or anything else we construed as “mainstream”, instead we were a mix of folkies and prog-rockers and we got our music from The Old Grey Whistle Test on TV and from John Peel and Alan Freeman on National Radio. But living in Gateshead we had an additional, very special source for our musical education, the local radio show “Bridges” on Metro Radio.

Bridges was conceived as a show that would build bridges between different musical genres. It would play anything: classical, folk, heavy metal, progressive, blues (in fact anything except Country and Western.) With high hopes on its first night … the DJ didn’t turn up.

In a state of panic a luckless and rather introverted sound engineer called Geoff (Jeff?) Brown was told that because he was the only person in the studio other than the producer, he would have to host the show. Despite understandable nerves, the show went really well. It turned out that Geoff was extremely knowledgeable about all kinds of music and the next week he was asked to host the show again, and again, and again.

Within a few weeks the show had “gone viral” (before that term existed) and it was all we were talking about at school. Geoff Brown became a local hero of sorts, for example though I never met him myself, my mate Dave found out which pub he drank in and became friends (we were in sixth form). Later on the great Alan “Fluff” Freeman guested on his show, an indication that he was starting to get attention outside of the region, but I digress.

One of our favourite musicians at the time was the guitarist Steve Hillage. In case the name is not familiar, here’s some background. He started out in the famous Anglo-french Jazz-rock collaboration band Gong, among his many achievements he was the guest guitarist on David Bedford’s arrangement of “The Orchestral Tubular Bells”, and he later went on to produce The Orb. He even got a joke on The Young ones:

At the time this story took place he had left Gong and was embarking on a solo career. His music was initially strongly influenced by jazz and Indian classical music, in fact here’s one of the albums we were all listening to. It includes a number of the members of Gong, including Didiere Malherbe and Shakti Yoni:

[the last two tracks were not part of the original album] I still love this album today, if you ignore the “tree hugging hippie crap” (South Park TM) you can hear great melodies, strong bass lines and extraordinarily melodic improvisations that never dominate but always compliment the music.

Anyway to cut to the chase, Steve Hillage was touring with his new album “L” (recorded with Todd Rundgren in the US) and was due to play Newcastle City Hall in a couple of weeks. Then Geoff Brown fatefully played a track from that album on his show.

Now Bridges, because of its wide ranging content, had an equally wide-ranging audience, including quite a few head-bangers and air-guitar players, and the track Geoff Brown played was this one:

It’s a cover of a Beatles song, and at the end, Hillage lets rip with a guitar solo the likes of which said head-bangers and air-guitarists had never heard before.

The outcome of this was that when Steve Hillage turned up at Newcastle City Hall a few weeks later, instead of the flower-waving patchouli oil smelling crowd that he was used to, the entire front of the theatre was full of leather clad biker types looking for a bit of excitement. And Steve Hillage had no security.

I was there.

Just after the concert (or possibly during the concert, my memory is vague) the crowd rushed the stage. Steve Hillage just stood there bemusedly as he was mobbed by dozens of these aggressive and definitely-not-hippie types, and I distinctly remember seeing his signature wooly bobble hat fly in to the air as people grabbed for souvenirs. I seem to remember seeing his left ear detached also, but I might have imagined that.

Anyway common sense and the theatre bouncers bouncers finally prevailed and we all went home. I understand the rest of the tour was uneventful, and Hillage even continued to make albums and tour after that, before the trauma of the event finally drove him in to the reclusive life of a music producer. He’s still doing well.

Addendum

The pressure finally got to Geoff Brown apparently. I heard gossip that he had a sudden nervous breakdown, among other things that I won’t go in to, but I do know for a fact that he left Metro radio suddenly with no announcement or explanation. He deserved better, Strange and sad.

Blender Tip – Perspective Clouds

The problem: how to texture a sky sphere with procedural clouds so that the clouds appear to recede into the distance at the horizon, rather than just being wrapped around the sphere. I searched around without luck for a way to do this, before realising that it’s so easy to do, however the maths isn’t going to be obvious to everyone so I thought I’d share this quick tip.

For those who just want the node setup, here it is.

Node setup for Perspective Clouds

However if you’re interested here’s a brief explanation. Im assuming you’re familiar with the standard trick of using a noise texture through a colour ramp as the factor to mix between a sky texture and a clouds texture (or in this case just a plain colour). I won’t bother to explain that bit. What we want is to be able to control the scale of that cloud texture so it gets smaller as the scale value increases towards the horizon. It turns out that the value we want is just the distance from our point of view to each point on an imaginary flat horizontal cloud layer somewhere above our heads. If we take the texture co-ordinate of any point on the sky sphere as a normalised vector, then the z component of that vector is the height above ground of the end of that unit length vector. All we need to work out then is how long we would have to make that vector to touch our imaginary cloud layer.

If we say the cloud layer is 1 unit above the ground, then when z is 1, the vector is pointing straight up and the required vector length is 1. If z is 1/2, then the vector would have to be length 2 to touch the clouds, if z is 1/3, then the required length is 3 and so on. So the length of that vector is just 1/z. Plug 1/z into the scale of our noise texture and bingo, perspective clouds.

Life Just Handed Me a Yellow Card

That’s what my GP said when he told me to ring 999 for an ambulance last Wednesday morning, 8:30am, 10th December 2014, after I phoned the surgery complaining of chest pains.

For those of my friends that don’t already know, I’d better say up front that I am now perfectly well and back at home.

Within less than five minutes of calling 999 I was in an ambulance being told “you are having a heart attack”. N.B. not “you have had” or “you are going to have”, but “you are having”. Scary stuff. I really didn’t know much about heart problems and had equated “heart attack” with “coronary arrest” which isn’t the case. A heart attack is when the heart muscles aren’t getting enough oxygen and start to complain, and later, if untreated, to die. Coronary arrest is when the heart actually stops. Apparently around one in five untreated heart attacks result in coronary arrest and in sudden death.

The ambulance crew were absolutely brilliant, talking to me,  letting me know what was happening and reassuring me that treatment was available and that the hospital could sort me out. They were also fantastic with my wife, Mary, calming her down when she walked in on the scene in progress.

Twenty minutes later I was being stretchered in to a hospital cardiology lab and surrounded by people. Within forty minutes they had found the problem and inserted three stents into my right coronary artery. This was painless, with only local anaesthetic and a catheter through my right wrist.

By 11am I was in the recovery ward, feeling none the worse for the experience, just exhausted. Two days later I’m back at home, actually feeling better than I have in months; I think some of my recent tiredness was related.

After that, only good news. Because of the operation, called a “Primary angioplasty”, my coronary arteries are nice and open and I am told I have less chance of having a heart attack than most people. I’m also told that there was only around 5% damage to my heart muscle so I’m very lucky.

I still have to reassess some life choices, think a bit more about my diet, do more exercise, and maybe loose a little weight, but I’m personally in a better place now than before this happened. I don’t think I can say the same for my family who were all scared half to death by the whole event, but I hope time will heal.

I must say that I’m in awe of the integrity, compassion and selfless commitment of all of the people I encountered in the NHS, truly one of the seven wonders of the modern world. They undoubtedly saved my life, as they have saved the lives of countless others.

I’m writing this to put my thoughts in order, to let everyone out there know what happened, and to avoid repeating myself in private correspondances. I’m also writing it to apologise for a few non-appearences at up-coming festive events; I’m going to be taking it very easy for at least the next couple of weeks. But basically life is still good, perhaps even better, despite the yellow card.

See you all in the new year.