Preprocessor Programming (All 9 parts as a PDF)

The recent series of articles about Preprocessor (Meta-)Programming is now available as a PDF file. Hopefully it is easier to read like this. It is about writing code which is evaluated with the C preprocessor.

preprocessor_preview

Click to view/download

The original posts have now been removed from the blog as they are all included in this one.

A Bit of Graph Theory

I’ve written a document which explains some basic graph theory. In particular, it poses a few puzzle questions related to planar graphs and then solves them using Euler’s Formula.

I tried to write it in a casual style. The idea was that it should be easy to read whilst not giving up any mathematical accuracy. Actually, I’m not sure the style works at all, but it was worth experimenting.

Thank you to Kris for some suggestions to improve it. A version suitable for A5 booklet printing is available on my website.

graph_preview

Click to view/download

Fever Pitch Quotes

I’ve just finished reading Fever Pitch by Nick Hornby.

It is an autobiography told though Arsenal football matches, and how the authors life interacts with them and reflects them.

The following are my three favourite passages from the book:

A critical faculty is a terrible thing. When I was eleven there were no bad films, just films that I didn’t want to see, there was no bad food, just Brussels sprouts and cabbage, and there were no bad books – everything I read was great. Then suddenly, I woke up in the morning and all that had changed. How could my sister not hear that David Cassidy was not in the same class as Black Sabbath? Why on earth would my English teacher think that The History of Mr Polly was better than Ten Little Indians by Agatha Christie? And from that moment on, enjoyment has been a much more elusive quality

The following goes some way to explaining how playing and watching football are completely different things, and the latter is not merely a replacement for the former:

One thing I know for sure about being a fan is this: it is a vicarious pleasure, despite all appearances to the contrary, and those who say that they would rather do than watch are missing the point. Football is a context where watching becomes doing – not in the aerobic sense, because watching a game, smoking your head off while doing so, drinking after it has finished and eating chips on the way home is unlikely to do you a whole lot of Jane Fonda good, in the way that chuffing up and down a pitch is supposed to. But when there is some kind of triumph, the pleasure does not radiate from the players outwards until it reaches the likes of us at the back of the terraces in a pale and diminished form; our fun is not a watery version of the team’s fun, even though they are the ones that get to score the goals and climb the steps at Wembley to meet Princess Diana. The joy we feel on occasions like this is not a celebration of others’ good fortune, but a celebration of our own; and when there is a disastrous defeat the sorrow that engulfs us is, in effect, self-pity, and anyone who wishes to understand how football is consumed must realise this above all things.

And it is worth remembering how bad most of us are at football – even the ones who seem great:

This is how close I came to becoming a professional [footballer]: at college, one or two of the first team (I was in the first team in my final year) played for the Blues, a team consisting of the eleven best players in the whole of the University. To my knowledge, two of the Blues players in my time went on to play at a professional level. The best one, the university god, a blond striker who seemed to glow with talent in the way stars do, played as sub a few times for Torquay United in the Fourth Division – he may even have scored for them once. Another played for Cambridge City – City, Quentin Crisp’s team, the team with the wonky Match of the Day tape and a crowd of two hundred, not United – as a full-back; we went to see him, and he was way off the pace.

So… if I had ranked number one in my college, as opposed to number twenty-five or thirty, then I might have been able, if I had been lucky, to look bad in a very poor semi-professional team. Sport doesn’t allow you to dream in the way that writing or acting or painting or middle-management does: I knew when I was eleven that I would never play for Arsenal. Eleven is too young to know something as awful as that.

“An Introduction to Primes & Proof” back online

An Introduction to Primes & Proof” is a ‘mini-book’ intended for readers who like mathematics, but want to learn more about it. In particular, it is for the transition from doing algebra into learning about proofs. As the title suggests, prime numbers are the vehicle for doing this. It introduces proof by contradiction (using Minesweeper) and proves the basic theorems about prime numbers.

Earlier versions carried on a bit, talking about the zeta function. These sections have now been removed in order to make the it easier.

View

Interface Metaphors Which Are Out Of Date

Today I was reading a book on UI design in order to prepare for a project I will be doing in a few months which will live or die by its UI. It stresses, as other books in the past have, about metaphors. The most famous metaphore is the Desktop Metaphor. Wikipedia describes it as follows:

The desktop metaphor treats the monitor of a computer as if it is the user’s desktop, upon which objects such as documents and folders of documents can be placed.

However, it occurs to me that interface metaphors which relate to previous ‘ways of doing things’ might soon go out of date. For instance, younger people now will not have seen VCR or cassette players. I’ve personally never seen a card index file system and other methods of manual storage. I’ve never actually used a filing cabinet either!

Another example of a metaphor which may not be seen very often in the real world might be a compass, as GPS devices can show maps in the direction that you are facing. Ledger books, polaroid photos, and physical address books (I even have to specify ‘physical’ now) could all go the same way.

So, when choosing a user interface metaphor, might we need to think if the youngest generation of computer users will resonate with it?

“When Things Going Wrong Is A Good Thing” (An Introduction to Complex Analysis)

I wrote this for a friend, and you can see that in the way it is written. Anyway, thought it might be of interest to some people.

complexanalysis

Spellcheck Object Guide

So it seems that nobody is too sure how to use the Spellcheck object. It is a pro-only extension, and it never had a step-by-step tutorial, so here one is. It is based on my post on the Clickteam Forums.

Stage 1: Load a dictionary

Obviously the spell-checker doesn’t work without a dictionary. Luckily, the example pack comes with two dictionaries. We’ll just use the smaller word list for now, but there is a larger one too. The larger dictionary includes some common spelling errors itself as it is based on common search terms, and so is best avoided.

Insert the object into the frame and don’t change anything on the dialog box. Most of these settings are only required for advanced use, and you won’t need any for a while yet.

Now, create a  ‘Start of frame‘ condition and add the Spellcheck action ‘Load Wordlist (Pauses MMF)‘, as shown in the screenshot below:

Choose ‘Smaller Wordlist.nswl‘ as the dictionary, which, as mentioned earlier, can an be downloaded as part of the example pack.

If you run the program, nothing happens. That is because it loads the dictionary, and then does nothing with it. If you are running on a particularly slow computer, or loading the file from a slow location, you might see a delay whilst it loads, but that is it.

We got to make it do something. Hence, stage 2.

  1. ‘NSWL’ stands for ‘Null separated word list‘. This means that each word in the dictionary is separated by a ‘null character’. (ASCII value 0). Words can also be separated by new lines, but as a new line in Windows is 2 characters using null characters saves a little bit of space.
  2. It is also OK to load one dictionary then another, and the object will then have a dictionary with both the details.

Stage 2: Checking if a word is in the dictionary

We can check if a word is in the dictionary by using the ‘Is Word correct?’ condition. So, let us make an edit box with a button which tells us what is the case.

Insert the button and edit box into the frame as you normally would. We wish to make to events: One which fires when the button is clicked and the word in the edit box has been spelled correctly, and the other when it is clicked but is not. For this, we will use the “Is Word Correct?” condition:

Add the condition “On Button Clicked” + “Is [Text of edit box] correct?” and provide some effect, like setting a string to “Is in dictionary”. Then have the same event but with the second condition negated and have it do something like set a string to “Is not in dictionary”. It should look something like this:

Run it and hopefully you will see that, for instance, “Hello” is in the dictionary but “Hellop” is not.

  1. For more advanced use you can load it in the background with the ‘Load Wordlist in Background‘ action and update a progress bar using ‘LoadingPercentage‘ expression, but for now we’ll just let it pause your program whilst it is loading. The frame cannot change before it has finished loading, though! Change the example so that it does it that way.
  2. All Spellcheck objects share the same dictionary, so if you load it on the first frame and use it again on the second, you don’t need to reload it. Test this by loading the dictionary and checking the words in different frames.

Stage 3: Getting suggestions

Now this is not very exciting. However, we can get suggestions using the object. To do this, you get the incorrectly spelt word and pass it to “List Suggestions” action. This doesn’t directly do anything, but it does cause the ‘On Correction Suggestion‘ event to get triggered once per suggestions.

So add a list box, and when an incorrect word is found you should clear the list box it and then call ‘List suggestions’, adding the suggestion to the list each time. Use the ‘Suggestions -> Get Suggestions’ (Suggestion$) expression to get the name of the current suggestion.

Download this as an example here

Tweak the settings on the first page of dialog box to change how the results are returned.

The Next Step

The next step is to spell-check sentences. This is explained in Part II.

Book: The Science and Politics of Global Climate Change

Book Cover

The Science and Politics of Global Climate Change: A Guide to The Debate‘ (C.U.P) by Dessler, a professor in the Department of Atmospheric Sciences at Texas A&M University, and Parson, a professor of Natural Resources & Environment at University of Michigan.

This is a simply written book explaining Climate Change in a scientific manor, which is beyond the quality you will find in books on the ‘Popular Science’ shelf, and of course it is written by scientists and not journalists. I found the second half of the last chapter, on the politics of it, slow and boring reading, but apart from that it was all very interesting, particularly the earlier chapters.

The second edition is out in March which will have a longer introduction to the science. No science knowledge at all is needed really. All technical language is explained.

There is no doubt at all that the earth is warming up, and it certainly seems as though it is caused by humans. Once this is established by reference to various data sources and other explanations (with strengths and weaknesses explained) it moves on to what should be done about it.

It won’t help some people though. To quote from a recent Telegraph blog written by an idiot:

[F]raudulent scientists have gained millions of pounds by taking selective samples of natural climate change, whipping up a Grande Peur and using it to advance the cause of world government, state control and fiscal despoliation of citizens.

2010 should be the year when all that ends. It is time for Zero Tolerance of [Anthropogenic Global Warming] fraudsters and their political masters.

Probably for people reading such conspiracy theories this book is more relevant.

Voodoo Histories

Ramsey Theory

I have written a short, 4 pages introduction to Ramsey theory. It has pictures. It covers basic existence proofs but not much else.

Title page