So last week I was in Tokyo, which means not much was going on at all. Or rather, so I had planned, but something amazing happened in the meantime. One evening I sat down to take a proper look at Caramel, the library I had intended to use for HTML manipulation/generation. I didn't like it. So then I thought back to what I really wanted. I wanted to have jQuery, but in Lisp. Not thinking too much about it, I opened emacs and wrote a small prototype function that would allow me jQuery like syntax. After about half an hour of twiddling around, I had a (wonky) first solution and it was brilliant.
Before I go into detail on how this works and why and whatever, I want to take a short step back and explain how HTML manipulation would work in Lisp without special syntax. Provided we have all the necessary functions available, you would end up with something similar to the following: font(Monospace){(append-to (parent (css (find document “article”) :display “none”)) (find document “#content”))} I don't know about you, but this does not look very appealing to me. In actual jQuery, this would've looked like this: font(Monospace){$(“article”).css(“display”,“none”).parent().appendTo($(“#content”));} This is a very nice approach as it displays everything that's happening and how as a pipe. Results pass over to the next function and get modified accordingly with the provided arguments. Lisp's “native” syntax is much harder to read. In any other language you'd have to create a new object system to allow what jQuery does. Any modifier function would have to return such an object instance and any modifier would have to be a method on this object. I was not up for wrapping everything into a new, complicated object system and re-implementing all the DOM manipulation functions that were already in the closure-xml-dom package. So what I did instead was write a macro that would allow me a similar syntax to jQuery, while relying on the same HTML objects that already exist. Thanks to my library I can now write code like so: font(Monospace){$(“article” (css :display “none”) (parent) (append-to ($ “#content”)))} Hooray! And the macro that does the heavy lifting for this isn't even big either! I was very, very happy at this point, because I knew I could do this. Writing this library myself would be actually possible! On the following couple of days I gradually wrote all applicable jQuery functions again in Lisp. I finished the last missing function on my flight back. So here I am, with jQuery in Lisp implemented in a matter of days. Of course, my implementation is nowhere as amazing as jQuery is, since it doesn't have to deal with platform differences and all that toot. It's also still very much unoptimized and might very well be buggy at certain points (I have yet to implement unit tests for everything), but it is quite amazing regardless that I managed to do this as quickly. I would have never expected such results. Once I have tested everything and implemented units, I will release lQuery publicly.
Other than that I've spent some time getting accustomed to ASDF, in order to make the build and load process easier. I've also begun thinking a bit about how to structure this whole mess. Before I can really go on though I need to take a closer look at Hunchentoot, so I can figure out how to interact with it as a webserver and how to properly utilize its power to embed TyNET in. This is a sort of roadblocker too, as my architecture heavily depends on these initial steps. Before I know how I can actually hook into Hunchentoot, receive requests and process them properly, I can only make bad guesses at how to write my init sequence. Starting tomorrow I'll be investigating that and once I have a working init sequence, I'll be back. Or, in case I get to writing unit tests for lQuery sooner, it'll be that.
Excuse the short entry, but I just wanted to give a quick heads up about what happened and what my immediate plans are. Plus, I was simply too excited about lQuery to keep this hidden for much longer. Next time: either lQuery Release or Hunchentoot Intro.
Written by shinmera