Tuesday, December 16, 2008

Abstraction = FPS

Lisp was created from a mathematical abstraction called the lambda calculus and when you use the language to its fullest you can see its roots. There are two things that higher mathematics does well, notation and abstraction. Mostly because mathematicians, like programmers, are lazy. This isn't a bad thing, it's just that the less notation there is the easier it is to understand the problem. I algebra we can say this:
e^(pi*i) = -1
This really does say a lot! It is a Rosetta Stone for all parts of modern algebra, from trigonometry, to complex numbers, to calculus. The best part is, it will work with all the numbers up to an including complex numbers. If we wanted to, we could find out exactly what types of number systems Eular's Equation will work for.

Lisp shares this power. Not only can it create any type of object; it can create objects that create objects! Since that is the case, this can continue as many times as necessary to complete a task. Therefore we can create infinite levels of abstraction to help us with our programming needs. It's like making an arm to hold in your arm held by another arm. It might be overkill but it can be done.

Which begs the question:
What can we abstract successfully?
My theory is, everything. The way I was taught was to pick a random example and see if I disprove the theory, so I will. I picked one of the most difficult types of programs to write, the first person shooter. I wanted something that people would not think needed abstraction. We play an instance of the game, after all! But there are game engines that specialize in the first person shooter. That might be a good place to start, but all that I have seen require certain things to be true. Like gravity, must always be down, or the game engine must be 3d and realtime. The idea of abstraction means all FSPs will follow this pattern. So far, I can think of a few that do not. Portal is a FPS that does not have static 'down' gravity or even a static idea of 'distance'. Maybe I wanted to create a first person shooter where you have to do a puzzle to shoot? Therefore the game engines are not a good place to start due to their restrictions.

Let's move up the ladder of abstraction, all video games require input from the keyboard and/or mouse and/or joystick. They all have output as sound and video. This is a good place to start. We can abstract the input and the two output types. Beyond that, since the input will occur asynchnously we can create an event messaging system. Well, we ususally have at least one camera and a menu as well. In fact, since all FSP games are 3D, we really just care about the game mechanics! All the window handling, input and output can be prewritten for any FSP type game. Then all that needs adding are objects, maps, sounds, music, events, and game rules. Wow! It looks like we can abstract even video games successfully. This is hardly a proof, but it shows what can be done.

There are many other ways to use Lisp to make life easier. Lately I've just been using the REPL as a shell for other things. Still this was a fun thought experiment. I would like to do something of this size but I don't have the time right now.

No comments:

Post a Comment