Thursday, 29 May 2008

YUI and Parenscript

Parenscript is a nice little mini-language that lets you compile Lisp to JavaScript. Sort of like Google does with GWT and the language to end all languages: Java.

Parenscript code looks like this:


(ps:ps
(defun say-hi ()
(alert "Hi!"))
(say-hi))


The macro ps:ps compiles the Lisp code to a JS string which looks like this:

function sayHi() {
alert('Hi!');
};
sayHi();

Notice the conversion from say-hi to sayHi. I love the Common Lisp naming conventions. They make so much sense and I miss them everywhere else. Obviously the writers of Parenscript agreed with me so they convert each symbol they see into a JS symbol which keeps things looking mostly neat.

The major conventions are (I don't know that there are more):

  • *foo* becomes FOO

  • foo-bar becomes fooBar

  • foo.*bar becomes foo.Bar



Anyhoo, YUI is a largish but nice JavaScript library that one can use for creating quite interactive web applications.

The problem is that YUI has names like YAHOO.util.Event.onDOMReady which is a handful to type even in JavaScript. If you try converting this symbol via ParenScript you will be in for a surprise (try it!) Anyway, there are a couple of ways to write this in ParenScript and keep the casing intact without losing your hair:


  • *yahoo*.util.*event.on-d-o-m-ready

  • |:YAHOO.util.:Event.:onDOMReady|



This works because the bars prevent the reader from downcasing or upcasing the symbol and ParenScript promises that it will leave symbols that begin with a colon alone.

Even so, this is still a PITA to type. What I do is I have a wrapper script that gets compiled once with short names for all of these. So for the above example, using Hunchentoot:

(defin-easy-handler (my-yui :uri "/ps/my-yui.ps") ()
(ps:ps
(defun yui-on-dom-ready (fn)
(|:YAHOO.util.:Event.:onDOMReady| fn))
(defvar yui-some-other-funky-name |:YAHOO.util.:FunkyChickens|)))


Yay.

Monday, 26 May 2008

30 day product challenge: update

The idea: Develop or prototype a commercial application in 30 days. Then decide what to do with it.

Initially I had thought this Wiki would be the central point for a uISV community but I should have known better. It appears that people are a lot more comfortable with using their own blogs to update progress.

With that in mind, Patrick McKenzie (a successful uISV owner, whom I greatly respect) has decided to jump on the bandwagon in his own way

I am joining up with him and will be starting in mid-June while I complete some other work.

I will be aggregating all the 30 day participants I can find at this feed

Best of luck and happy coding!

Friday, 23 May 2008

Very cool interview with a compiler developer

Its sad that this is interesting for me but when you are waiting for a large C++ project to compile (gtkmm), you listen to these things in the background:

The route to C++ code optimization

The C++ compiler is the best MS product that exists. Well the only good product... Or maybe I just have a soft spot for C++ compiler developers. Either way, this man (also) uses Emacs (the illegal version) so maybe there is more to the story.

Channel 9 people: You need to have a whole series on the C++ compiler from top to bottom.

Wednesday, 21 May 2008

Public service announcement: urxvt (rxvt-unicode)

One good habit I have picked up over the years is to have a separate environment for each project that I am working on. For example, I might want to work on project foo but to do that, I need /opt/foo/bin to be in the path. So what I would do in the bad old days is:


$ cd /path/to/project/foo
$ export PATH=`pwd`/bin:$PATH
$ export OTHER_VARIABLE=OTHER_VALUE


Obviously, this can get annoying fast so I would put it in a script and then do the following:

$ cd /path/to/project/foo
$ source setup_environment.sh


The problem with the above is that it involves two more manual steps. Grr... Fortunately, most terminal emulators have the option to execute a script when a certain "profile" of the shell starts.

I have been using gnome-terminal as a terminal emulator for a long time and it has an option to execute a shell script as described above. Unfortunately, when setting the shell script to run in Ubuntu 8.04 through some pointy-clicky magic, it crashes *all* my windows. I don't even know how its managing to do that. On top of that, setting the script to run is quite unintuitive to me. So with these two things together, I finally got fed up and installed rxvt-unicode.

This program is blazing fast. The only thing I'm missing is tabs but I hear that is possible as well. urxvt uses the Xdefaults file which you can use to set system-wide or application specific options for X programs. The relevant settings for me look like this:

URxvt.background: black
URxvt.foreground: green
URxvt.scrollBar: false
URxvt.font: xft:Bitstream Vera Sans Mono:pixelsize=13

There is a daemon that you can run in the background (call like urxvtd -q -o -f) which you would run when you log in. This daemon starts all urxvt terminals within the same process which can save memory but has the disadvantage of taking all your terminals down if one crashes (which I presume doesn't happen too often!) To request a new terminal window, use the program urxvtc.

Back to my original point (I have one?), given that your shell starting script looks like this:

#!/bin/bash
# Usage: start_foo_shell.sh

cd /path/to/project/foo/
pushd $1
source setup_environment.sh
bash


You can set up shortcuts to start in that shell by using the command:

# Start a shell for feature_foo
urxvtc -e bash /home/sohail/src/foo/start_shell.sh branches/feature_foo
# start a shell for trunk
urxvtc -e bash /home/sohail/src/foo/start_shell.sh trunk

This ends the public service announcement. You will be returned to your regularly scheduled feed reeding.

Monday, 19 May 2008

Boost.TR1 package

For those of you interested in using only the TR1 portion of the Boost C++ libraries, you can download a package I created for this purpose. It is about as lightly tested as things can get. I just used bcp to extract everything and copied the minimal amount of stuff needed to run the TR1 tests.

For those of you who don't know what TR1 is, see the Wikipedia page on TR1.

Anyway, you can download the package here (OS indicates line endings):



Steps to running TR1 tests:

  • Download one of above and extract

  • cd boost_1_35_tr1

  • cd tools/jam/src

  • ./build.sh or build.bat

  • export PATH=`pwd`/bin.*:$PATH or set PATH=%CD%\bin.ntx86

  • cd ../../../

  • cd libs/tr1/test

  • bjam


The above will only run the TR1 tests. I just noticed that the regex tests are missing. If anyone cares, leave a comment and I'll see what I can do.

To use in your own code, read the Boost.TR1 documentation.

Also, this is in no way official, so please don't bug the Boost guys if you have a problem. Bug me instead :-)

Sunday, 18 May 2008

30 day product challenge: taking registrations!

I originally made a post here outlining that I think a 30 day product challenge for developers would be an interesting experiment. Others seemed to echo this sentiment.

The intent is for this to put you front and center so that if you fail, you look really bad ;-) Hey, it works for me!

So, in the spirit of something every two days, I have started a wiki here:

http://30dayproductchallenge.com/30day/FrontPage

You may register for the challenge simply by creating an account (go to the bottom of the page for the link!) Please be sure to subscribe to the FrontPage after you register so that you can be notified when the challenge starts.

Thanks to Phillip Flores for motivating me to get things set up.

It is quite probable that the site will buckle under the load of more than 5 people simultaneously accessing it ;-) If this happens to you, please keep trying!

Wednesday, 14 May 2008

Lisp compiler for .NET

I've always wanted to write a compiler for Lisp and .NET. And tonight I did both! Ok I lie. It only handles strings right now but my plan is to add some type inference soon and see how things go. This would not be any sort of faithful lisp implementation as it would be a bearable skin on .NET. To me, that would be worth the work.

Input:


(import "mscorlib")
(assembly "hello")

(defun print-it ()
(print "Hello! How are you?")
(print "I am fine!"))

(defun main ()
(.d entrypoint)
(print-it))


MSIL output:


.assembly extern mscorlib {}
.assembly hello {}
.method static public void PRINT_IT () cil managed
{
.maxstack 1
ldstr "Hello! How are you?"
call void [mscorlib]System.Console::WriteLine(class System.String)
ldstr "I am fine!"
call void [mscorlib]System.Console::WriteLine(class System.String)
ret
}
.method static public void MAIN () cil managed
{
.maxstack 1
.entrypoint
call void PRINT_IT
ret
}


Program output:

sohail@dev-ubuntu-wks:/tmp$ mono foo.exe
Hello! How are you?
I am fine!


Now I can go to sleep!

Wednesday, 7 May 2008

BoostCon '08

I gave an all day workshop on Boost Serialization yesterday. I was a bit nervous as I hadn't really tested the material elsewhere and I think the BoostCon organizers were also nervous as they had never seen me work my magic. Fortunately, I had a few gems in there and my section on forward compatible file formats with the serialization library was my favourite part. For my money, I think people got the most out of it because there were a few practical activities in the session (though we didn't have time for all of them.)

Anyway, at the end of it, one of the attendees said that it was likely going to be the highlight of their week which is a great review for me! For what its worth, I don't think that there is any way the session could have gone as well as it did without the amount of dedication the attendees had so I am very grateful to them. So many of them stayed throughout the breaks to work on their activities! That was awesome of them and made me want to make sure that they "got it" even more!

Now I am heading to the keynote by Bjarne (who seems to be walking around in a hat to remain anonymous?) That will be a highlight for me, but really, giving that presentation with those attendees is the ultimate highlight.

PS: If you ever want to live on the wild side, try and get people to compile Boost in your presentation. That was "fun" but paid off once people had things working.

PPS: In my opinion, the *first* session for everyone in BoostCon should be geared towards getting people compiling and running Boost.