Category: Sci/Tech

I’m missing Scheme (by )

I've not done any Scheme programming for ages. In fact, the past few months have been quite a haze of relentless hard work; I'm liking what I'm actually doing for a living, except I've been doing rather a lot of faffing about recruitment rather than actually doing it lately.

I'm having to spend half of my week in London, and the other half working from home - but with Sarah away that half of the week doing her course, I'm working from home alone by day and looking after Jean in the evening, while having my working day bracketed by taking Jean to and from nursery, which is a half hour round trip each way. All the thrill of commuting without the fun of working somewhere different to where you sleep, or with people.

So, no programming-for-fun lately! But that can't last forever, since trying to stop my mind from going exploring for too many months in a row is always rather futile.

So I came across Ventonegro's post on and-let* and it set me thinking. The Lisp family of languages (which includes Scheme) are renowned for their macros, which are the key rationale for the minimalist syntax; without things like if holding a special place in the language, user-written macros are just as powerful as anything that comes built into the language. This lets you extend the language with features that you'd be mad to build into a language core, but which are nonetheless useful reusable constructs, such as and-let*.

As an aside, let me just explain and-let* - the name is a terse mnemonic that makes sense to Schemers and nobody else, but it's a way of compactly writing bits of code that attempt to compute something in steps, where the trail might end at any step and fall back to some default. The example Ventonegro gives is rather good:

  (define (get-session request)
    (and-let* ((cookies (request-cookies request))
               (p (assoc "session_id" cookies))
               (sid-str (cdr p))
               (sid (string->number sid-str))
               ((integer? sid))
               ((exact? sid))
               (sp (assq sid *sessions*)))
      (cdr sp)))

Which translates to:

  • If there are cookies available
  • And there is one called session_id
  • And parsing it as a session id succeeds
  • and the session id is a number
  • and that number is an integer
  • and that number is exact (eg, 3 rather than 3.0)
  • and that number is the ID of an existing session
  • ...return that session

A few languages happen to make that pattern easy to write natively by putting assignments inside an and, as Peter Bex points out, but with Lisp you don't need to rely on the that piece of luck; you can roll your own luck.

There's a whole library of useful macros and combinators (another handy higher-order programming tool) in most Scheme systems, and any your system lacks can be copied easily enough. But it occurs to me that there's very few educational resources on actually using them. I think a definite theme, if not a whole chapter, in a "practical Scheme" book would have to be the introduction and then applied use of such handy macros (and a damned good reference guide to them all), because reading the definition of and-let* failed to really fill me with inspiration for situations I'd use it in. While reading Ventonegro's example reminded me of some ugly code I'd written that could be tidied up by just using and-let*.

It's great to be able to assemble your own syntactic tools, but presenting them as one unorganised mass will just make your language seem as complex and messy as C++ and Perl combined; yet sticking only to the core base language and expecting programmers to spot their own patterns and abstract them out results in duplication of effort, and every piece of source code starting with a preamble full of generally rather general macros, neither of which are good. Rather than choosing a tradeoff between the two, as static programming language designers are forced to, we need to find a way of cataloguing such tools so that they can easily be split by category, and by priority; so the ones that are most widely useful can be learnt wholesale, and ones that are more useful in certain niches can be glanced at once then gone back to and studied if required.

The van is fixed! (by )

After the van's sad demise, it went off to Sarah's excellent uncle David to be fixed.

Anyway, he sorted it out, and I picked it up last weekend, but I've only had a moment to write about it now!

Basically, the front right wishbone had broken. It's a big triangular metal thing that attaches to the chassis on two hinges, and then attaches to the wheel at the other end, with the shock absorber coming down into the middle. As the van rides over bumps, it pivots on the hinges, regulated by the shock absorber. So it plays an important part in supporting the weight of the van.

However, knowing I'd be interested, after replacing it with a new one, David put the broken one in the van for me to take a look at!

A broken wishbone

I'd have expected something like this to be a solid casting - but no, it's two pressed sheet steel shapes welded together, making a hollow body. It looks like thick steel, 3mm or so, but near where it's cracked apart, it's more like 1mm. I presume that's due to corrosion over the years.

A closer view of the break

Here's the new one - in situ, under the van. It's the shinier, blacker, cleaner looking part, although it's already picked up quite a bit of mud.

The new wishbone

The old one is now in the little garage, awaiting cutting apart to investigate its construction and exact reason for failure, then WELDING PRACTICE!

Lava Domes, Fracturing and Earthquakes (by )

Last Tuesday I went to the Meet the Post Doc's semaniar at UCL there were two speakers the first one was Rosie Smith with Evidence for Seismogenic fracture of Erupting Silicic magma. This was interesting becuase it was looking at the fractures that occure like in the mouth of volcanos where the magma (hot rock) is pushing upwards. This means that the rocks are hotter than normal rocks that are being deformed by say mountian building events and so the fualts break and fracture and then some of them basically anneal shut again - the fracture heals its self or the rock sort of glues itself back together again.

Again these faults and their behaviours will affect the volcano-tectic earthquakes. It is also interesting to me from a structures point of view and the effects all this fracture and annealing will have on say the minerallogy and the structural integrity of the resulting rock.

However the bit that really intrested me was her talking about the apparatus she uses to simulate what is going on - they put the rocks in machines that squash them and heat them and there are obviously alot of constraints and alot of issues as to weather the sample has been treated to get rid of water and all the rest of it.

I like these types of machines and would love to use them - they can also test the aucostics of the sample so I assume they can basically hear the fractures occuring and then propergating through their samples. However you do not seem to be able to control all three axis of stress even though it is called a Tri-axial deformation apparatus - there is also an issue with thermal gradants through the samples if you are say heating it from just the bottom etc.... they are designing new equipement which sound fun too 🙂

Earthquakes and their Recurrance times (by )

Last Monday I had a lecture on Fualting and Earthquake mechanics with Gerald Roberts - I'm not going to say I enjoyed this lecture becuase to be honest I found it mostly depressing.

I also both agreed and disagreed with the Gerald. Basically I will not be convinced that the apparent data skew as you back through Italy is a real data skew and not just people not recording or being in the right place to record the earthquakes - until I have seen a distrabution map of the monastrys and seen some sort of formulisation of how complete each monestries records is. Then I'd want to know what rock the monstries where standing on and therefore what sort of ground motion they would be expecting for each magnitude which I feel could dangerously biased the data - ie if they are on more ridged rock and modern towns aren't (I dont know if this is the case this is a 'suppose') then they may not have recorded the right sort of level of damage and there would be an underestermate for devastating earthquakes.

Having said all of this I do actually think he is right in the main points that he is putting across and as for those bits I doubt - I want to see the evidence and not just take his word for it - the same goes for his earthquake intensity diagram I think I understood how it was made but I don't think it was explain in a way that is going to get through to the poeple who need to listern to him.

Now the bit that I found very depressing is that earthquakes are assumed in all predictive models to have 475 yr reccurance - earthquakes can be produced by movement on a fualt now the strain builds up and up until the fualt shifts. But they are assuming that this happens at a steady rate but if you just think about snapping sticks in half this doesn't seem logical. They will break with a sort of concentrated judder. If this is happening with earthquakes then it means that you would expect a cluster or group of earthquakes to happen along a fualt one after another and then have a period of no activity whilst the strain builds up again.

Now Gerald has been measured slip rate which is I would of thought one of the first things they would have looked at with earthquake prediction - I remember doing the maths behind working the slip rates during my undergraduate so why has it been ignored? Plastic deformation ie mountian building, folding etc... is generally a precursor to the breaking of the rocks that is the fualting and thus the earthquake inducement and you measure this in strain rates which shows that for the middle of the 'crumple' zone or mountian ridge like the apanines in Italy the rate of deformation (how fast its folding up) is faster than that at the edges. So surely this means that the middle will have more earthquakes, larger and closer together.

But this is not mirrored exactly in the earthquake hazard maps produced currently as they assume this 475 yr reoccurance. This is for everywhere on the planet but they will be subject to different forces - why on earth did they get this sort of age from anyway?

Now his work shows that some fualts have longer re-occurence ages than the writen records we have - now Italy had the Romans so they have 3000yrs of records and they will still miss things - Gerald pointed this out himself. If you preject what he is saying to his risk maps then what you have is away of telling if a fault has shifted all its going to for this lot of earthquakes - this is where this become counter intuitive to poeple who haven't been looking at it in detial - areas that haven't had earthquakes for about 400 yrs are safe for thousands or at least hundreds of years rather than being about to blow (which the used maps suggest) and faults that shifted within the last century is going to go again anytime soon.

Now he showed us fualts that are behind where they should be - great you can warn those areas but then showed on the same map that there are fualts that are ahead for there earthquake quota so should be fine for ages.

This last point concerned me - if this is to be a useful tool it needs not to have faults that are ahead of themselves in the number of earthquakes they have had - the number you;ve predicted they should have had in that period of time - though over all the earthquake is expected as while the zone is active there will be strain and then slip but if there where unexpected earthquakes there then there will be when you actually project the technique into the future.

So this means you can say this area is going to have an earthquake soon but no where can actually be ruled out - now you could argue that they live in a tectonically active country they need to expect earthquakes and that is great but where should they prioritize their money for building reinforncement and the such like. Gerald thinks they should do all of it all at once but from a government perspective I doubt this will look feasible and would infact look unreasonable and there is no point in ramming facts about affects on economy of such big disastors as they are going to be getting that sort of statement from everyone about everything.

Yes I feel that as many of the buildings should be a safe as possible starting with the obvious infastructure buildings - anything new should be built properlly to begin with. Again this is heavily affected by the ground the buildings are on.

This was the bit that always makes me so depressed - he said that in Italy about 3 yrs ago there was a small mag 5 earthquake that hit a town and the only building that collapsed was the school, during the day killing about 50 kids - this sort of thing hurts me in physical scense. I don't know if it is becuase I was brought up with the nightmare shadow of the result of Aberfan where a slag heap berried a school in Wales - this happened to be where half my family where from (they were from Merthyr Tydfil to be precise though my nan was from somewhere even smaller). It was talked about with heart broken whispers when I was a child. My second cousin was involved with the rescue attempt.

I always get the guilty feeling that all this disastor management stuff or climate change stuff should be what I use my geology for but I would not be good at it - I would be doing it out of obligation and not passion. I feel I would be better off and more lickely to find something that will actually help people by researching something I am interested in and just talking to other geologist and scientists about their fields. The earthquake stuff is still depressing me though.

Linear Dunes (by )

Last Wednesday I had an interesting lecture on the Linear dunes of the Namibia from Charlie Bristow he specialises in modern sedimentary environments. I have always liked sand dunes I really enjoyed all the Applied Sedimentology course I did at Imperial except the petroleum bits and even quiet alot of that I found interesting.

The premise people had been working on was that these huge dunes where left over from the last glacial maxium but this turns out not to be so. There is cool dating techniques you can use on sand that has been sitting in the dark - you get like an exposure date for the last time it saw sunlight as the sunlight 'bleaches' the sand grains and sets the exposure age to zero.

I remembered from before that there where three types of motion on the sand dunes - there are little sort of parasitic dunes moving across the huge great big stonking dunes for a start. It is/was thought that these types of dunes do not appear in the geological record so they where of interests becuase of that but in cutting into the dunes it is now thought that they might look simialar to other types of dunes - dune morphology and how they look inside due to migration (the wind blowing them sideways or back to front or whatever) is actually a bit of a geometric nightmare to get your head around especially when you start looking at how a paloe (old turned into rock) dune bed can be exposed - it could be tilted, cut at a strange angle and all sorts.

Anyway the dunes are younger and would appear to be able to tell us about climate changes that may have occured in the area - this includes looking for 'fossilise' hirax poo but these are rare. There are also fulgurites which are the formation you get when lightning hits sandy substrates which supports the idea of climate change which would have produced vegitation ie it got wetter - it started to rain and plants grew their root sort of stoped the dune sand from being blown about.

I suggested they look for root material which is apparently on the cards.

WordPress Themes

Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales
Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales