Skip to content
Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Lisping towards enlightenment

elbeno, 17 December, 200729 December, 2007

Me: a C/C++ programmer of 12 years (professionally), a Lisp dabbler (programmer is too strong a word to use here) of, let’s say ~3 months. I’ve done enough functional stuff to be comfortable with that side, but I haven’t (hadn’t) yet written a project big enough to get me used to Lisp syntax.

The project: an LL(1) parser. That is, given a suitable grammar and set of legal lexemes, produce a function that will (top-down predictive) parse legal strings of said grammar. This isn’t rocket science by compiler standards, and I’m not sure it’s even likely that the grammar I have in mind to parse can even be made LL(1), but I have implemented precisely this in C++ before, so it’s a good test. Straight out of the Dragon Book section 4.4.

So far I have completed Lisp functions to produce a parsing table, using appropriate algorithms to construct First and Follow sets. This is about 110 lines of Lisp. Looking at the old C++ code (about 5 years ago) it comes to about 230 lines. From this I conclude that even a newb like me can gain immediate benefit from Lisp, and that I don’t yet know enough Lisp to make this about half the size it is (e.g. I’ve used no macros).

Time taken to get this far in Lisp: about 2 days. Time taken to get this far in C++: unknown, but the entire thing (grammar design, lexer, parser, bytecode compilation & VM execution) took on the order of a few months. The C++ version is production code that shipped in a real life game. Make of that what you will.

Even after 2 days, I’m already fine with the brackets. They really do not bother. The code is readable through indentation. I do sometimes run into problems with misplaced brackets when editing code, but it’s akin to a syntax error which is immediately found and fixed. I expect this to go away as I get more proficient.

Lisp Programming

Post navigation

Previous post
Next post

Related Posts

Experimenting with (cubic) Bézier subdivision

27 February, 20081 March, 2008

As you know, a Bézier curve (here meaning specifically a cubic Bézier) is often used for drawing all kinds of things in vector graphics. It has the nice property that the endpoints and control points form a bounding box, and deCasteljau’s algorithm is a nice numerically stable way of evaluating…

Read More

More on ellipses

1 March, 20081 March, 2008

I think I will use the same method as I do for Bézier curves to step along the circumference. Another generalisation I had to make from the circle code is with respect to the normal. For a circle of radius r, centred on the origin, and parameterised by angle θ,…

Read More

Concurrency in games

5 August, 20075 August, 2007

I’ve been programming next-gen consoles for a while now, and I have to say: it’s not getting any easier to write games to take advantage of multi-core systems. The conventional wisdom at my company is: writing multithreaded code is hard, so “ordinary programmers” should not be doing it – let’s…

Read More

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

©2026 Why is a raven like a writing desk? | WordPress Theme by SuperbThemes