Clojure is a Lisp for the JVM. I don’t normally like Lisps - the code tends to feel cluttered, and the libraries are scattered and difficult to penetrate. Whilst in Python you’d perform a ‘import string’, in PLT Scheme you’d have to ‘(require (lib "string.ss" "srfi" "13"))’.
Clojure solves that by having a small, functional core, and farming everything else out to Java. It works surprisingly well, and the code ends up looking rather clean. It’s rather similar to Arc in style; with short function names, a small core, and liberal amounts of simple syntax sugar. Where Clojure differs is it’s more functional style, it’s advanced concurrency primitives, and it’s integration with the Java.
Neverwinter Nights and its sequel use a custom scripting language called NWScript. Why Bioware didn’t use something like Lua, I’m uncertain, but reinventing the wheel isn’t exactly a rarity in the software industry.
NWScript is very much like a cut down version of C. Unfortunately, it lacks arrays, or any form of list-like data structure. This makes designing complicated scripts in it rather trickier than it otherwise would be.
To this end, I’ve created nwn.ss, a PLT Scheme module for turning a custom S-Expression into valid NWScript.
I’m a little dissatisfied with the libraries available for authoring web pages in Haskell. I want something that takes full advantage of Haskell’s do-notation to produce simple, readable code. Something like this:
main = httpServe 8080 $ do GET "/hello" ==> index index :: Reader HttpRequest (HttpResponse -> IO HttpResponse) index = do name <- param "name" setHeader "Content-Type" "text/plain" output "Hello " output name
I’m still a way from finishing it, but I’ve managed to create a HTTP request parser and a basic server. I’m aiming for a initial 0.0.1 release that will allow me to specify fixed outputs for any valid HTTP request:
main = httpServe 8080 (output "Hello World")
From there, I hope to add features with each release, until I have something usable. The code will be available under a MIT license.
Sometimes, when working in Ruby on Rails, I find myself writing code like:
foobar = FooBar.find(:first) default = foobar.name if foobar
In Haskell, this would be a classic usage case for the Maybe monad. In Ruby, we don’t quite have the capabilities to make it implicit, but we can approximate the behavior explicitly:
class NilClass def maybe(*a); self; end end class Object alias :maybe :send end default = FooBar.find(:first).maybe(:name)
A small hack perhaps, but it saves a bit of typing.
As a general rule, I find I’m not happy with a software project until at least the third ground-up rewrite. Rewriting is usually discouraged in business, and not without some good reason. But in my spare time, I often find myself happily refactoring my code, each design better than the last, but never quite getting any further before I spot some flaw that inspires another redesign.
Haskell seems to encourage this constant honing, not just for complex modules or sophisticated libraries, but even for the smallest function. It’s refactoring in miniature; a sort of code bonsai.
I was recently trying to create a netstrings implementation for Haskell, and I started off with a function that would strip the first length indicator off. So for instance, “5:hello,” would become (5, “hello,”)
readLength :: String -> (Int, String) readLength s = (read n, tail s') where (n, s') = break (== ':') s
This was my first attempt. Did it work? Yep! Could I do better? Maybe…
Ever heard of ISBL?
You’d be forgiven if you hadn’t. Wikipedia devotes only a single sentence to it, and you’re unlikely to find it mentioned in any database textbook. It’s a relational database language that was developed during the 1970s at IBM’s UK Scientific Centre, around about the time that SQL was being spawned in IBMs US labs.
ISBL never took off, whilst SQL became ubiquitous. This is a shame, because ISBL was an elegant system that used only six query operators, and was firmly based on Codd’s relational model; conversely, SQL was a mixed up mess of inconsistent keywords and terrible design decisions.
In today’s SQL dominated world, modern programmers may be sceptical of my opinions. Sure, SQL may have it’s quirks, but it’s not that bad a language - is it? Rather than lecture you, I’ll provide an example…
I was recently faced with the task of turning a table of database results of the form:
A B D A B E A C F A C G
Into an XML structure like this:
<A> <B> <D/> <E/> </B> <C> <F/> <G/> </C> </A>
The language I originally used to solve this problem was C# 1.0, which involved a while loop and a lot of conditions to check state. This is a rather inelegant solution; what I’d like to have done is taken a step back, and written a more generic function that converts any arbitrary table of results into its corresponding tree. C# lacks the tools to do this with any ease, but for Haskell, such abstractness is second nature.
I’ve recently been playing around with wmii, a very minimal window manager for Linux. It uses a virtual filesystem to allow third party scripts to interact with it, in the style of procfs or Plan 9. ruby-wmii is just such a system for Ruby, and I’ve been spending an interesting time trying it out.
I’m not sure whether I like wmii yet, but I’m willing to give it a chance. It’s very minimal, but it’s nice to be able to have windows automatically tile, and I rather wish there were some way of doing it in GNOME or KDE. Maybe I’ll come to like the minimalism as well, but for now it seems there are a few things missing that could be rather useful.
One of these useful but missing things is a way to monitor network traffic, but it’s not too hard to add it. I’m just surprised that someone hasn’t created a plugin for it already. Briefly, then, here’s the class I use to poll for traffic information…
Every so often, some deep seated instinct stirs within me, and I get the inexplicable urge to program a computer game. It never lasts for long, as my interests shift constantly, and projects I have no financial stake in rarely hold my attention for any substantial length of time. But my interests are cyclical, and so I make progress in increments, short bursts of activity before my curiosity wanes.
I’ll be posting some of the better snippets of code from the last time I had the compulsion to create a game. I had decided to create a Roguelike in Python, and so needed a set of functions to handle your classic Cartesian coordinate planes.