Exercise 1A

So I’ve been working on the first of the PSP exercises. The requirement is to write code that calculates the average and standard deviation of a linked list.

My first attempt hasn’t ended in failure, so much as the realisation that I took the wrong approach. I’ve marked this down as a design defect in my error log.

The emphasis really ought to be on the standard deviation and not on the data structure. I’m writing in Lua, a language which among other things includes a flexible standard data structure called ‘tables’, which can at various times behave like arrays, hashes, stacks, queues and so on.

My next revision of the code will focus on using tables as-is, rather than bodging up a linked-list structure composed of tables with two elements. I expect it will probably be much easier to write, too, due to Lua’s support for easy iteration over table structures.

This entry was posted in PSP. Bookmark the permalink.

3 Responses to Exercise 1A

  1. dave bath says:

    no interface between lua and glib available – it has some gorgeous linked list etc handling.

  2. dave bath says:

    sorry should have been a question mark not statement about lua and glib. hell, if you are lucky, it might be internal.

  3. Jacques Chester says:

    Googling around I see a binding to GNOME, including Glib. But really I didn’t need it: the inbuilt table structure covers the problem of aggregating numbers into an iterable data structure.

Leave a Reply

Your email address will not be published. Required fields are marked *