Category: The Family

Lambda bodies in Scheme (by )

So, if you look at a recent Scheme standard such as R7RS, you'll see that the body of a lambda expression is defined as <definition>* <expression>* <tail expression>; zero or more internal definitions, zero or more expressions evaluated purely for their side-effects and the results discarded, and a tail expression whose evaluation result is the "return value" of the resulting procedure.

I used to find myself using the internal definitions as a kind of let*, writing procedures like so:

(lambda (foo) (define a ...some expression involving foo...) (define b ...some expression involving a and/or foo...) ...some final expression involving all three...)

But the nested defines looked wrong to me, and if I was to follow the specification exactly, I couldn't intersperse side-effecting expressions such as logging or assertions amongst them. And handling exceptional cases with if involved having to create nested blocks with begin.

For many cases, and-let* was my salvation; it works like let*, creating a series of definitions that are inside the lexical scope of all previous definitions, but also aborting the chain if any definition expression returns #f. It also lets you have expressions in the chain that are just there as guard conditions; if they return #f then the chain is aborted there and #f returned, but otherwise the result isn't bound to anything. I would sometimes embed debug logging and asserts as side-effects within expressions that returned #t to avoid aborting the chain, but that was ugly:

(and-let* ((a ...some expression...) (_1 (begin (printf "DEBUG\n") #t)) (_2 (begin (assert (odd? a)) #t))) ...)

And sometimes #f values are meaningful to me and shouldn't abort the whole thing. So I often end up writing code like this:

(let* ((a ...) (b ...)) (printf "DEBUG\n") (assert ...) (if ... (let* ((c ...) (d ...)) ...) ...))

And the indentation slowly creeps across the page...

However, I think I have a much neater solution!

Read more »

Death Head (by )

For the last year - maybe a little more I have felt that I am dying - I don't mean the ageing existential dread - I mean the feeling that my blood was thickening and clogging, as if it had hooks and barbs, but that if I was to get cut it would just bleed and bleed and bleed, that my heart was struggling with every beat but that there were so many of them that it might explode with the effort instead. My lungs have been fire, my ribs still hurt to breath as if I am breathing nothing but acidic smoke or drowning. My back hurts in new and unexpected places and this dull ache reminds me of the infected kidneys and sure enough my water works are... not right. My head often feels like it is literally being crushed or that ice water and electricity are somehow being poured into the brain casing. Then there are my muscles - so week, and crampy, twisting into painful shapes if not just the extremities going numb or tingling sometimes changing colour to match. My body feels like it has been shutting down whilst running the engine at full throttle. I actually feel like I am vibrating sometimes, my sternum is sore and even between my ribs... if I cough its like there are bands of barbed wire wrapped around too tight. And my eyes feel like they are being pushed out of my head by thumbs pressing in from the inside of my skull. My bones sometimes feel like they are splitting apart and even my teeth and scalp hurt. This is of course all on top of the pain I already had from old injuries, the chronic pain, migraines and the womb of doom.

It feels like I've been dying by degrees. Not helping this is the fact I do also have the existential dread - I have just had two and half years of everyone dying - so so many friends and family and the miscarriages and the almost dying myself. The spring especially this month is particularly horrendous for anniversaries and rememberings - including dad's and of course my last outing before illness and Lockdown was a funeral - the world beyond my door is filled with death.

But the absolute worst thing about all of this is that I can not dismiss it all as a panic attack - I did that in the summer and ended up being rushed into A&E - I am lucky I didn't have a proper heart attack - I am lucky once more to be alive. My heart really is struggling, I have been quiet sick since the miscarriages and then caught flu and/or covid on top. I have had seizures and my eyes are actually being pushed out of my head by the muscles at the back of them inflaming. My blood is clotting in a non good way and then not clotting when I need it to seal a wound. My breathing sucks - I sound like my dad who had COPD. My poor body is being pumped full of adrenaline so it is running at full throttle and it is tired - I am literally shaking myself apart like a poorly maintained piece of machinery.

I spent most of last year being unable to sleep flat due to my lungs and my hair keeps falling out.

I even got new allergies and warning sighs that my body was trying to reject parts of itself - like during my pregnancy with Jean - then there was the yellow skin - to go with the red blotches and weird blisters.

For 3 months last year - starting around now - I could do nothing much other than survive and since then basic parenting and washing myself have kind of taken up ever ounce of energy. My eye sight and hearing have both been affected and this too is not helping - it makes it like the world has receded from me - even with my new awesome glasses - and that is how ill I have been - I haven't even properly shown the world my fabulous sun glasses. I have been unable to write or draw or even craft - I began making tentative steps back to the things I love doing in the autumn but it seems like such a steep climb. Two weeks ago I attempted and completed my first commission since March last year - I managed it - I am starting to fight back - but it is unbelievably hard and I do not know where the bounders lay between physical illness and say - not seeing any of my friends for a year - most of them more than that as my mobility has been shot since the miscarriages.

The kids are helping me - we have started a family art club but I am feeling like the worst fail parent as my 15 yr old cooks food to feed the family whilst attempting GCSEs and the 10 yr old gets into trouble at school because they are obsessed with death and won't shut up about it. They both thought I was going to die and Mary got to see a full blown seizure and didn't know what to do and went to get help but everyone thought they were just doing a please play with me and so she came back and sat in the room telling me to stop and asking if I was ok and it was awful. And the poor Alaric too - they have had to take on everything -- including the basics of looking after my mum and trying to work and fill in the gaps of homeschool I got too tired to do - and there was a lot of it - I fell asleep in Mary's school club zoom. Alaric had the horror of watching me decline once more and feeling that everything is balanced on them and their ability to work and look after and fix and clean the house.

Alaric is somewhat crushed and I am more than aware of this and can do nothing other than attempt to make occasions out of everything. So today I am making a "Fake Away" of the King of the Golden Archers variety - so nuggets and burgers and milkshakes (yes that is me mucking around with the concept of Burger King and McDonalds!). The kids actually like helping with these events and tend to do their chores without arguing and they also know that these things sometimes get postponed if I am too ill - hell Jean got her birthday cake last week - her birthday is in August though Mary's happened on time - though her cake was rock hard in an attempt to make and not buy when too ill to really cook - she loved it and has been eating it with dairy free custard. This is how I fight back - it is a little lame that is true but then I am a lot lame.

But also the last couple of weeks the feeling I was dying started to lift. Obviously the seasons and things are changing so it could be the sunlight - but then I had the summer last year so I don't think it is that - I think that maybe all the medicine and things are working - I am classified as extremely clinically vulnerable and as such have already had my vaccine - I should have had weeks before I did but I got confused as I am trying to deal with 5 peoples worth of appointments and some of the clinics over lap. Three of the household are taking medicine and three are attending clinics - there isn't a complete overlap of the two groups either. Both kids now count as SEN I think and Jean is being supported by young carers.

A phrase keeps getting stuck in my head the Gloucester themed Beatrix Potter story - "I am worn to unravelling" - I am worn to undone - but the fight is on.

I now weigh the most I have ever weighed outside of pregnancy and that is some feet as I lost a couple of stone during the fever etc last year - so my weight has seriously been fluctuating with a 5 stone difference - I realise part of that is the thyroid meds (as in you can lit chart it to the dosage) but a lot is also my mobility (and maybe too many FakeAways coughs) and I was over weight to begin with.

Part of my fight back is trying to exercise - but seriously it is like trying to run a marathon every day when all I am trying to do is get up the stairs :/ but I am currently managing 3 odd km with crutches or half a km on the treadmill with out. I am using gaming (PokemonGo) and bribes (medals) and do gooding (charity challenges (or rather will be for this one)) to get moving again - before they went back to school the kids did PE with Joe with me and we found another youtube who does work outs to musicals (I found these easier to get into than Joes stuff that is obv aimed at the smol peeps).

This week has only involved one lot of blood tests and a panic at remortgaging - I have turned 40 and didn't get to have my big party but I got a purple coffee machine and though I am worried about the amount of waste it produces I have to say it is currently being my go to when things get too hard and it is like having a coffee shop in my home and mum only really likes coffee shop hot drinks anyway... we are struggling in every way except money at the moment - which is weird and I have to say money has definitely made a big difference and I can not lie about that - I have the home coffee shop set up and Netflix and iPlayer and Prime and Crunchy Roll and an epic gaming set up like we have never had before. But I often think that somewhere there is a me - trying to get through all of this without those things - and I have been in that place and in such a place it was impossible for me to fight back and all I could do was survive with lots of help. And so I want to help others - I have been trying - we have sent food and money to food banks, given resources to scrub hubs and the Hackspace to make PPE etc and I made halloween parcels for friends I thought might be finding things tricky but was too ill to even send Christmas greetings on line 0.o

Its swings and round about - but it is at least something and part of my fight back of me living is trying to make this world a better place.

So I am currently a Death Head but do have High Octane blood and hope a little engine over haul will help with things - it's just a little tricky as it has to be left running whilst the maintenance work is being done.

Recap - I feel/felt like I'm dying - probably because I actually was - trying to do more than survive and get myself as well as I can - have traumatised family due to the almost dying bit and not seeing any friends and family (big issue for youngest who needs kids to run around with and has been very lonely) - focus on family emotions rather than on grades or outside assessments. It is the anniversary time for lots of the deaths of people I love this month and also I will probably be hitting people up for sponsorings for charities to help get me fit because my arse is way too big. Also also all grown ups in our household have now been vaccinated first doeses for a few weeks which is an emotion boost even if it scrubbed me out for a week and a half (nothing like actual covid).

The Polyp Mixer (by )

So, on my desk I often have a desktop computer and a laptop. I've got a decent HDMI/USB KVM switch so I can flip my big monitor, keyboard and mouse between the two, and that's great.

However, I also have a hi-fi amplifier and speakers for audio output. This is hooked up to the desktop PC, and has selectable inputs, one of which is connected to a lead for the laptop - but I rarely plug the laptop in. This is because I can only select one input on the amplifier; and although I'm usually only listening to media from one device, I want to be able to hear notification pings from either. So I tend to leave the laptop on its own nasty little speakers and only have nice audio from the desktop PC.

Clearly, this sucks. Many years ago I had a cheapo mixing console that sat on my desk, with my CD player, minidisc player, and PC connected to the inputs, outputting into my amplifier; it was cool to be able to just hit play on anything and hear the result through my good speakers, and having all those knobs and sliders to play with was definitely gratifying. However, it was bulky, full of useless-to-me features like phono inputs and cross faders, and eventually died a death from being left switched on all the time.

Plus, I'd recently resolved to do more electronics, so there was only one thing to do: Make a mixer.

The Polyp Mixer

Read more »

Receipt printer hacking (by )

So, for Christmas, I got a receipt printer. It's a Jepod JP-5890K, the important specifications of which being:

  • Mains powered
  • USB connectivity (appears as a standard USB printer)
  • 58mm wide thermal paper rolls (widely available, cheap)
  • 384 dot horizontal resolution
  • No automatic cutter, you need to tear the paper off yourself
  • Costs less than £30

I asked for this thing because I noticed I was using a lot of Post-It notes to basically copy stuff down off the screen, and automating that seemed fun.

Read more »

Scoping generic functions (by )

So, my favourite model of object-oriented programming is "Generic Functions".

The idea is that, rather than the more widespread notion of "class-based object orientation" where methods are defined "inside" a class, the definition of types and the definition of methods on those types are kept separate. In practice, this means three different kinds of definitions:

  1. Defining types, which may well be class-like "record types with inheritance" and rules about what fields can be read/written in what scopes and all that, but could be any kind of type system as long as it defines some sort of "Is this an instance of this type?" relationship, possibly allowing subtyping (an object may be an instance of more than one type, but there's a "subtype" relationship between types that forms a lattice where any graph of types joined by subtype relationships has a single member that is not a subtype of any other member").
  2. Defining generic functions, by providing the structure of the argument list (but not the types of the arguments, although in systems with subtyping, there may be requirements made that some arguments' types are subtypes of some parent type) and the type of the return value and binding that to a name.
  3. Defining methods on a generic function, which are a mapping from a set of actual argument types to an implementation of the function, for a given generic function.

Note that the method refers to the type and the generic function, and is the only thing that "binds them together". Unlike in class-based OO, the definition of the type does not need to list all the operations available on that type. For instance, one module might define a "display something on the screen" generic function taking a thing and a display context as arguments; this module might be part of a user interface toolkit library. Another module might define a type for an address book entry, with a person or organisation's name and contact details. And then a third module might provide an implementation of the display-on-screen generic function for those address book entries. All three modules might well be written by different people, and only the third module needs to be aware that both the other modules exist; their authors might never hear of each other.

This is good for programmers, in my opinion, as it makes it easier to build systems out of separately-designed parts; it exhibits what is sometimes called "loose coupling". In a class-based system, the author of the address book type would either need to be aware of the user-interface toolkit and make sure their address book entry class also implemented the "display on a screen" interface and declare an implementation of the UI logic (which might not be their interest, especially if there's a large number of UI toolkits to choose from), or users of the address book class in combination with that UI toolkit would need to do the tiresome work of writing "wrapper classes" that contain an address book entry as an instance member, and then implement the display on a screen interface, and have to wrap/unwrap address book entries as they move in and out of user-interfacing parts of the application.

"Ah, but what if the user inherits from the address book entry class and implements the display-on-screen interface in their subclass?", you might say, but that's only a partial solution: sure, it gives you objects that are address book entries AND can be displayed on screen, but only if you explicitly construct an instance of that class rather than the generic address-book entry class - and third party code (such as parts of the address book library itself) wouldn't know to do that. Working around this with dependency injection frameworks is tedious, and success relies on every third-party component author bothering to use a DI framework instead of just instantiating classes in the way the language encourages them to do. An ugly solution, when generic functions solve the problem elegantly.

It also provides a natural model for multiple dispatch. Class-based "methods within classes" mean that every method is owned by one class, and methods are invoked on one object. In our address book UI example, the generic function to display things on screens accepts two arguments - the thing to display and a display context. In a class-based system, this means that the display method defined on our address book entry is passed a display context argument and can invoke operations on it defined by the display context class/interface/type, and if it wants different behaviour for displaying on a colour versus monochrome screen (remember them?) it needs to make that a runtime decision. However, in a generic function system, there would be separate subtypes of "display context" for "monochrome" and "colour", each defining different interfaces for controlling colours. This means you can provide separate methods on the display GF for an address book entry in colour or monochrome or, if you didn't need to worry about colour as you just displayed text in the default style, have a single implementation in terms of the generic "display context" supertype.

This feature is particularly welcome for people writing arithmetic libraries, who want to define multiplication between scalar and matrix, matrix and scalar, matrix and vector, vector and matrix, vector and scalar, scalar and vector, etc.

You can use run-time type information to implement all of this in a single-dispatch system, but (a) it's tedious typing (in both sense of the word) for the programmer, (b) it is not extensible (if somebody writes a "multiply" method in the "Matrix" class that knows to look for its argument being a scalar, vector, or other matrix, what is the author of a third-party "Quaternion" class to do to allow a Matrix to be multipled by a Quaternion?), (c) this robs the compiler of the opportunity to do really fancy optimisations it can do when it knows that this is a polymorphic generic function dispatch.

However, generic functions present a big problem for me, as an aspiring functional programming language author: scoping.

Read more »

WordPress Themes

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