Wednesday, August 13, 2008

Documentation Viewer

This project isn't very exciting, but it will be useful to me. I wrote a documentation viewer that displays documentation information in a tree control.

I spent a lot of time going through the Python library documentation, acquiring what I thought was important, and re-organizing all of the modules into my own categories. This also required writing Python scripts to turn reStructuredText, the loose and readable format of the Python documentation, into the xml format used by the doc viewer.

I also organized all of the documentation for C.

One cool feature is that it can communicate with the SciTE code editor. So, when run from LnzScite, it appears like a tool window, and you can double-click a function in the browser, which will insert the function's name into the editor. (Watch for this in Launchorz 0.3). A planned feature is to be able to look up documentation on the currently selected function.

I wanted this program to feel small and lightweight, so I did this: the nodes are created dynamically, from the xml, when you expand a parent node. This means that the entire documentation isn't loaded into memory and no unneeded TreeNodes are created. I also spent time tuning the xml-parsing code to be very fast, using C#'s stream reader which avoids DOM overhead.

You can download the Lnz Doc Viewer here, which includes documentation for C, Python, and LnzScript (unfortunately only for Windows). The source, as usual, can be found from the project page.

As an aside, I'm starting to take advantage of some of the benefits of xml. In the source for Launchorz, there are special comments for the provided functions. Everything starting with /// is treated as a documentation string, and can be processed by a Python script into an xml file. This xml file contains the prototypes and docs for every function in lnzscript - and the same file is used by a c# program, a c++ program, and a wsh script. And it doesn't stop there - if you open the same xml file in a web browser, it nicely renders the documentation with xslt!

Friday, August 8, 2008

AI Scheme

Just for fun, a few days ago I wrote a minimax AI algorithm in Scheme. This was mainly a way to become more familiar with writing in Scheme, and so I wrote it from scratch. I had written pieces of Scheme a year ago but wanted to write something more practical. Writing in a functional language is fun because it pushes you to see problems from a new perspective. (For those unfamiliar with the concept, of the code I wrote there are no variable assignments, for loops, while loops, or C-like arrays). Also, when finished, I was able to format the code nicely.



To use this algorithm, you can provide definitions for create_new_table,get_open_spaces,place_at_position, and is_winning, and that will be all you need. This zip file contains the complete program and an example game implementation.

If I get tired of S-expression syntax, JavaScript is actually a good language for functional programming. It has the ability to do concisely express things like function() { call_something(); return function(){ do_something(); } }(); or function adder(x) { return function(y) {print('!'); return x+y}; } f = adder(1); f(1);. In fact, it did not take very much work for all of the The Little Schemer examples to be written in JavaScript; see Douglas Crockford's page and this. Python's lambda, on the other hand, is intentionally limited to containing one expression, and there not seem to be any convenient way to create an anonymous inner function with scope.

Monday, August 4, 2008

Version 0.2!

Launchorz 0.2
Documentation

I've just released version 0.2 of Launchorz. It comes with significantly more features, and even a dedicated code editor. If you're using Windows, it will save you a lot of time. Try it!

The code editor is a custom build of Scite. I've added autocomplete and tooltips to make it faster to write scripts.

See screencasts here

Download it here!