Lisp Interpreter

I’ve begun work (say… about 8pm last night) on a piece of software that even after one day, I’m very proud of. It’s a Lisp interpreter.

Lisp, as some of you might know, has an incredibly simple syntax that makes it great for writing interpreters for. So that’s what I’ve been doing. At the moment, my software can take an S-expression from either stdin or a file, and create a syntax tree. It can also print out said syntax tree into the original S-expression.

I’m now fleshing out the details on how I want the core of the interpreter, the Eval() routine, to work. I’ve decided I want to use a Forth-like system of primitive and non-primitive words. So identifiers in my symbol table will point to either a syntax tree, which can then be Eval()ed further, or to a machine-code routine.

The hard part about doing things like this is getting machine code loaded into the interpreter system. I’ve come up with a few methods to do this:

  1. A dynamically linked library (.so / .dll) with symbol table entries pointing to their addresses within this library. If I do it this way, I can create a new library of routines without having to create a new interpreter binary. The only problem is, I don’t know how to create dynamic libraries.
  2. Vaguely the same idea as a dynamically linked library, but not using the proper method. That is, compile down to machine code and store the routine in a file with a format of my devising. I think I could do this, but I can’t remember from my operating system knowledge whether it will let me execute code in a data section (which is where the loaded file would be stored).
  3. Compiling the library right into the interpreter. I don’t really want to do this, but I will if I can’t get the other two to work. It is however, the easiest.

I’m looking for people’s input on how they think I should do this. I really have no idea. I can see a lot of flaws in all three methods. So maybe I am missing something.

I’ve learned a lot already. Namely:

  1. If you’re writing function that returns a linked list and it isn’t working, make sure return(List); is written in the function somewhere.
  2. Segmentation faults are never fun. Neither are syntax errors.
  3. English Breakfast tea along with Breakaway chocolate is great. But not in the same cup at once.

Hopefully I can decide what I want to do. If I can, expect a primitive release sometime in the next week or so.


The definition of happiness is one of the greatest philosophical quandaries. Proposed definitions include freedom from want and distress, consciousness of the good order of things, assurance of one’s place in the universe or society, inner peace, and so forth. – Happiness

In this essay, I will attempt (although I will only be scratching the surface with 2000 words) to show you what happiness may be, and also what it is not, for that is equally (if not more) important. I say ‘attempt’, because as the quote shows, the definition of happiness is illusive. I will also try to demonstrate how we can be happy, not through making more money, or by suddenly gaining new friends, but by changing our perspective on our situation. I will also differentiate between pleasure and happiness.

For several millennia philosophers have been unable to find a full answer. So I cannot show you the full answer, because there may not be one. It also may change, and be different for different people. And ever present, the dual dynamites of time (the five weeks spent on the Inquiry project) and space (the 2000 word limit) are going to have an impact on the fullness of this essay. I will only have time to touch on the broader aspects on which happiness may be contingent. It is impossible to construct a definitive list. I will not, for instance, cover freedom and personal liberty in detail, although these are very important factors .

I will to touch on health, wealth, and spirituality, and their role in happiness. I will mention belonging, and the importance of identifying with a group. I will conclude that happiness is a state of mind, and can be affected by our approach to and perspective on life. Happiness is not a concrete thing, for everything is transient (including, much to some people’s surprise, happiness).

So what is happiness? For reasons of clarity, and to demonstrate the difference between the two , I first want to define something else. That is, Pleasure. Pleasure is the state of being pleased, being made to feel good, but only in the short term. Things that can bring us pleasure include sex, the high of drugs, and good food. But pleasure is not the topic of this essay.

Instead, the topic of this essay is something much harder to define. So hard to define, in fact, that most people get it totally wrong. One could say that happiness is just pleasure. But if that is the case, then being pampered continuously would be the ultimate. But we look at so many rich western people today, who are constantly enjoying all of life’s ‘pleasures’ (decadence and hedonism), but are unhappy. The confusion between pleasure and happiness makes many people search in the wrong places all their lives. They search for pleasure, when they want happiness.

So what are the basic building blocks of happiness? One of them is health. Without the basic abilities to be able to walk, talk and think, a person is going to find it very hard to think positively. If a person is in extreme pain, they are going to find it virtually impossible.

Pain is bad when it comes to happiness, therefore looking after our health is good. Since scientists have all agreed that drug abuse, alcohol abuse, smoking, and bad diet are all bad for our health, one could safely conclude that indulging in an of excess these things are going to have long term negative consequences, even if they seem good for our short term ‘pleasure’.

But becoming sick, having an accident, or catching some disease can have constructive elements . Like the age old proverb ‘what doesn’t kill us makes us stronger’. Take, for example, Christopher Reeve, who played Superman in the movie. He had a tragic accident involving a fall off a horse, and was paralysed from the neck down. Yet Reeve was able to call himself a ‘lucky guy’. Reeve realised how fortunate he was to still have a working brain, and added that with less luck, he would have been dead after his accident (He died on the 11th of October 2004, many years after his accident). He also saw how there is more to life than material goods. His experience gave him the ability to notice things he didn’t notice before.

But some people in the Western World do not see this. They stumble blindly through life, looking for happiness in all the wrong places. They look for happiness in houses, in fast cars, in jewellery, in high-status careers, and in money. They are looking in the wrong places.

Having a nice house and a nice car might be ‘pleasurable’, but it is not essential to happiness. After a while, a large mansion becomes part of everyday life. Its appeal wears off after a while. A modest house can seem like the nicest thing in the world to those who really need it. In a personal experience, I was bush walking around Lake St. Clair, and after a day walking in the cold and the wind, I could not have appreciated a half damp tent that kept me warm and dry during the night any more than I did then. So a nice house and a nice car helps us be happy, but it is not essential. Neither is jewellery, or basic material wealth. It definitely helps not to be in debt. The stress of being in heavy financial debt does not help happiness, but again, it is not essential to happiness to be completely debt free.

To many people, wealth is status. Having the largest house, fastest car, or best career is the way to get status. They expect people with less money, and who have a lower position, to bow underneath them.

Many of them also want to have power. Power over other people, so they can get what they want (money, friends, status) with greater ease. But this want of power will come back to haunt them. Unless they can get total power over the whole of the human population (several people have tried to do this and failed), they will not have complete power. And if they do not have complete power, then there is always more power they can have. So wanting more power will to make them unhappy, because it is highly unlikely they will get it. The human condition is such that it always wants more power. Unless we can get this power, we will be wanting, and not be happy.

Everybody wants to belong. We see it everyday in the school yard. Most people spend their entire high school life trying to be accepted, to fit in, and to find friends. This is natural human behaviour. But what if we spend so much effort trying to be accepted by people who aren’t going to accept us, that we just become unhappy because we are not part of that elite group? This is where belonging can lead to unhappiness, because we are failing to get something we want.

But belonging can also make us very happy. We all, whether we want to or not, belong to our families. In times of need, when we are feeling sad, depressed, angry, or just need somebody to talk to, we can go to our families. They are incredibly important, because unless something drastic happens, we always have somewhere we belong. Love is important as a concept, but it is very complex, and cannot be discussed here.

The most important lessons here are that we must be content with what we have, and not want more, and not want less. Take the middle way, as the buddhist teachings keep trying to tell us.

And this brings us to the topic of religion. Buddhism, Christianity, Islam and many other religions have a guide, or a set of rules, for living. In Buddhism these are called the eight-fold path, and in Christianity these rules are called the Ten Commandments.

These rules (or guide, depending on the religion) aim to keep us out of trouble. They basically tell us to not partake in activities that benefit us the in short term, but at the cost of long-term happiness later on. Take for example, the Christian commandment of not stealing (Thou shalt not steal) . It tells us not to steal, however much we may want to at the time. This is because we will feel guilty afterwards, as well as the fact we will hurt somebody else in the process. Both these things will detract from our happiness in the long term.

Happiness is mostly about perspective, in that we can be happy just by choosing to be. We can alter how we perceive a situation, and what would have previously made us unhappy before now makes us happy. It is the same as thinking a glass is half full instead of half empty. Whether we are feeling happy or unhappy at a given moment often has very little to do with our absolute conditions but, rather it is a function of how we perceive our situation, how satisfied we are with what we have.

If we are satisfied with what we have, we will be happy. As an example, take two people, both of whom are earning $30,000 a year. The first thinks being paid $30,000 is sufficient. He can live happily on this amount. The second person can also live well off this amount, but they think they should be paid $40,000, because that is what the guy down the street is earning. Who is going to be happier? The first person, of course. He has all he needs to live, and also what we wants. But the second person, although he has all he needs to live, wants more. Now we give the second person a pay rise to $40,000. He is still not happy. Although he can live well off this amount, the person down the street is now earning $50,000, and our second person wants to match this. This relates back to perspective, and how we view our situation. This changing of our mind is not easy, as the following quote shows:

Achieving genuine happiness may require bringing about a transformation in your outlook, your way of thinking, and this is not a simple matter. We essentially have to appreciate what we have. We sometimes get so caught up in all the mass-media advertising that we fail to see that we already have what we need to be happy, and instead are just following our wants in order to find short-term pleasure. If we take the time to step back, we can see what we really need, as opposed to what we only desire. Doing this will help us see what will make us truly happy, and what will just bring us pleasure.

The human brain has to accept change. We must accept that everything is constantly changing. The weather changes. The seasons change. And if we do not accept it, we become unhappy, because we are wanting the past. We must accept the present. At the end of summer, when we has gotten used to the heat, it changes. Autumn comes, and we have to deal with the sudden cold. There is no option to keep summer, and we must go through autumn and winter, whether we like it or not. If we accept it, we can get on with our lives, and the cold doesn’t seem so unbearable. If we choose not to accept the fact autumn has come, we live in want of summer and the heat it brings, and are unhappy, because we do not like the cold. The rest of our lives are ruled by the same principle. If we accept change, we can be happy.

In this essay I have argued that happiness and pleasure are not the same thing. Pleasure is short term, whereas happiness is long term. Happiness is related to a number of factors, which include health, belonging, and religion. True happiness does not have any foundation in hedonism, decadence, wealth, or power. I have discussed the concept of perspective, and its relationship with comparison to other situations. I have also discussed change, and how we must accept it if we are to be happy. If we want to be happy, we must adopt a mindset. A mindset where we accept change, and look upon our situation in a positive way. It is about whether we see that glass as half full or half empty.