Wednesday, November 12, 2008

(RE Comments go here!!!)

The more I write the more I love lisp; especially when I am not using it. I know, this sounds like another "I love lisp!" blog post. Well, it is and it isn't. Let me start with what happened the other night while I was working on my computer...

I was playing around with clsql, a lisp library that lets me talk to databases and I was getting tired of writing something, copying it to another place, deleting the old copy and finally saving it. Since I was working with a database anyway, I wrote a quick function to take a function and "keep" it. At first I added a name argument to the front, but I realized I didn't need it because I could just look at the function call itself. I also had a type argument for functions and macros that I didn't need for the same reason. After a few minutes I banged it out and started using it. The code was now in the database and I could recall the latest version, or any version, of any function or macro I wanted.

And this was good...

But every time I went to "keep" something I had to move to the front of the function, type "(keep" and a quote. The quote was annoying me so I changed "keep" to a macro. This way I could just get the new code as data without adding the quote before it.

And this was also good...

But I was still unsatisfied. After thinking for a moment, I figured it out: I could write macros that would replace defun and defmacro! A few minutes of typing later I had "fun" and "mac" macros. (ripped from arc, so here is your credit) Now I updated the database with every function and macro I made. I have other things I want to keep but this was a great start. Now all I do I pull my functions from the database. This isn't a bad situation, I've basicly created my own function level source code control system. There is one issue, however. I can't keep the comments. I thought I could overide the single-character-macro-function for the duration of the macro but I haven't yet. Still, I can keep comments in the documentation string or in a do-nothing macro called "RE". It's not perfect, it returns a nil, but it's good enough. I'm finding out, this isn't a bad way of doing comments. I can define "RE" to be anything I want it to be, such as tracing code. And now I am off on a tracing/commenting system.

I told you all that to tell you this:

Lisp allows me to create simple things simply. It's unique interface makes changing my programming environment easy while still being useful. If you have not tried lisp, you must. I don't know how programmers (including me) did things without it. I don't know if it is a perfect language, but I am certain a perfect language would look a lot like lisp.

No comments:

Post a Comment