Ventruing into Lisp

Posted by Doug Tue, 20 May 2003 15:16:00 GMT

I’ve been writing Emacs:EmacsLisp for a couple of years now (and using emacs for many, many years). I like the style of Lisp. I’ve read lots of Paul Graham. He writes over and over again how things that are “impossible” in other languages are possible in Lisp. He’s claimed for years that working in Lisp is a competitive advanatage because of the power and flexibility it gives you more than any other language. Of course, as an elitist programmer, I want to believe this. The problem is I’ve never gottem much chance to experiment with it in real life applications outside of extending emacs (I’m trying to collect as much of that type stuff on my CategoryEmacs page).

I’ve recently been presented with a problem that lends itself particularly well to Lisp. One of my clients is “subscribing” to some data from a large vender. That vendor is providing it as two 15MB XML feeds. My first thought was to use Perl’s XML::Parser. For better or for worse, XML::Parser choked on it. I’m sure I could have made it work if I had fiddled with some of the more advanced features. What I wanted though was to simply $my parser = new XML::Parser; $parser->parserfromfile("foo.xml"); and move on to using the data. Proponents of Lisp have claimed that XML is Lisp for people afraid of parentheses. It seems Lisp should be a natural win for parsing XML.

Indeed it is. I’ve been struggling quite a bit though. Once I got some hand-holding I was able to use James Anderson’s CL-XML loaded into Steel Bank Common Lisp it was only about five minutes later I got (setf my-xml-data (xmlp:document-parser "foo.xml")) to work on the first of my 15MB files. The hard part has been knowing how to work in Lisp. How do you compile Lisp? How do you load libraries? How do I make sense of these compiler errors? These are things I intimately know for other languages but that I’m having to learn from scratch with Lisp. The other big problem is that cl-xml doesn’t seem to be documented very well to users like me. It makes heavy use of the Common Lisp Object System (which I don’t know). So, this whole process has been a baptism by fire.

The good news is that I’ve made some progress (Marc if you’re reading this that’s good news for you). I’ve managed to generate SQL for a big piece of the XML file. There XML data is broken up into “markets”. Each market has four main objects: offers, boltons, features, and promotions. I’ve managed to generate the SQL for inserting the offer data from a single market. I think this code is going to be very similar for the other three objects. So, I’m going to try and take advantage of Lisp’s ability to write code that generates code here. I’ve written just over 100 lines of Lisp so far. I don’t actually think it will take much more than this to do the whole thing. I’ll keep you posted.

Posted in  | no comments

Comments

Comments are disabled

Copyright 2001 - 2005 by Lathi.net and Doug Alcorn

Creative Commons, Some Rights Reserved Ruby on Rails Developer Powered by Debian GNU/Linux Powered by Typo