(A cheesy homepage for Justin Collins)
More Brattiness: Interactive Brat

Pretty much any language these days has to have some kind of interactive mode for playing around and testing things out. So I have been considering for a while how to make an interactive interpreter for Brat.

Now, Neko comes with a little interactive console itself (nekoc -console), but of course that is for Neko, not for Brat. Frustratingly, Neko has a lot fewer ways to inspect itself and do dynamic stuff like evals than you might think. For example, there is no way (that I know of) to grab a binding from somewhere and use it.

Since Neko (and therefore Brat) is compiled to bytecode, I wasn’t sure there would be a way to get this all to work. On top of that, Neko modules are each their own little world, with only “exported” values being available outside.

Long story short, I was getting really discouraged while considering how I could possibly accomplish this. Trying to understand even how the Neko console worked was annoying, because most of the Neko stuff is written in C or NekoML.

But I figured out a way!

However, let me whin- I mean, explain one other frustration. When I translate Brat to Neko, I use a ton of local variables. I do this because I figure they are more likely to be garbage collected and less likely to mysteriously screw things up. But the way the Neko console maintains “state” is by copying over global variables between evaluations. So I wasn’t even thinking about that as a viable solution.

So what did I do? (Seriously, get to the point, right?)

First of all, I needed a way to input Brat code without saving it to a file, and then a way to emit Neko code without saving that to a file. This I accomplished the first by reading in Brat code from standard input. From there, it is easy enough to interpret it and do whatever with it.

Then, I needed a way to interpret the code. This I accomplished by mangling the Neko console code to fit my needs. I was able to create a new executable which reads in Neko code from the standard input and evaluates it.

But, wait. What about those local variables? That was easy enough. Simple replacement was sufficient, and, as a bonus, variables that can remain local without trouble are not touched.

When the interpreter first starts up, it sets the same things as are at the top of a regular Brat program: importing and setting core functions and objects. However, instead of executing the code within a method on base_object (like normal), I simply set this to be base_object and everything works.

The two programs (the brat script and the neko_console) communicate via pipes. It all seems to work fairly well.

I even have a very simplistic “unfinished line” detector so things like functions can span multiple lines.


Brat syntax change

I realize that Brat owes a lot to Smalltalk, so I was looking over the Smalltalk wikipedia page.

I noticed that the syntax for blocks (functions) looked like this:
[ :param | ... ]
That made me think about Brat’s function syntax, which looked like this:
{ | param | ... }

Why is the Brat syntax like that? Well, because I am used to Ruby, where that is what blocks look like. But I noticed something. In Ruby, there are two vertical bars around the parameters. Why? I assume because of parsing issues, especially when you consider that curly braces are also used for hash literals. But, in Brat, square braces are used for arrays and hashes, curly braces are only used for functions. That means the first vertical bar is completely superfluous!

So I changed it to look more like Smalltalk, thereby saving a character and reducing syntactic clutter:
{ param | ... }

It does look a little unbalanced to me, with only that one vertical bar there, but I think that is just because I am used to reading Ruby. I am sure it will grow on me.

Note: This does introduce some ambiguity when you consider that ’|’ can also be a binary operator. In the situation where this could be ambiguous, the formal parameter interpretation has higher priority.

number.| = {rhs| my + rhs }
x = 1
f1 = { 1 | x }  #this is not ambiguous, numbers cannot be formal parameters
p f1  #=> 2
f2 = { x | x }
p f2 5  #=> 5
f3 = {| x | x }
p f3  #=> 2

Unit testing

I haven’t really gotten into the test driven design or unit testing stuff before (mainly because kams would require some serious “test harnesses” and I didn’t do that back when I should have), but since I started this new Brat project I thought it would be best to start off with some nice unit tests. In fact, it’s a pretty awesome thing to do when you are working on a grammar and a parser and you need to know what breaks.

But I’ve also discovered another benefit to unit testing: the psychological aspect. It seriously feels good when you see:
Started
......................................
Finished in 6.355985 seconds.

38 tests, 105 assertions, 0 failures, 0 errors

And I’m just getting started :)


My own little language

I think pretty much every programmer (every computer scientist?) dreams of one day writing their own totally awesome programming language. I know I have wanted to do it for a long time. But it’s such a pain…I mean, you have to write grammars and parsers (lexers, too, maybe) and intermediate languages and compilers and maybe a virtual machine to run it on…it’s quite a lot of work and headache.

But then I saw _why had all of a sudden written his own little language called Potion and I became really jealous. I wanted my own little language, too! It wasn’t fair :(

So I caught the bug. Seriously. The language implementor bug. The stars had aligned just right, though. I knew about PEGs from a class I took last year and Alessandro’s Ometa. I had heard of TreeTop, which is a PEG generator for/in Ruby. After a quick look around I saw the Neko VM, which provides a high-level language for…well, implementing languages. Then it compiles down to its own byte-code and runs on its own little VM.

With these tools in hand (and my vague memory of a compilers course), I have been working feverishly on a little language I am calling Brat. Why “Brat”? Because it’s a language for people who don’t like their language getting in the way of doing whatever they want.

So far, I have some basics implemented, like objects and methods. It’s sort of an object-oriented prototyping dynamically typed something or other. I guess I don’t really know.


New kams release and I’m sick

I’ve released a new version of kams (0.2.0).

Today is the first day of the new quarter, but I don’t have class and I’m sick. So I’m staying at home. Yay.


Adobe Flash player for 64-bit Linux? Soonish?

Adobe hasn’t given the 64-bit world a lot of love. Linux, in particular, tends to get the short end of the stick, typically receiving the latest version months after all the websites have upgraded.

But I just found out that Adobe just put out a new alpha version of Flash Player 10 for Linux (available here ) a couple days ago. It’s pretty raw (no installer), but I uninstalled the RPM version and copied the .so file from above to /usr/lib64/mozilla/plugins/

It seems to work alright so far.

Unfortunately, this may not be that great a cause for optimism. Other people thought 64-bit Flash was coming soon a few months ago.


Gnome-terminal Blinking Cursor

Okay, I noted a few months back that I and many other people noticed and hated that the Gnome terminal all of a sudden did not have an option to turn off the cursor blinking, but was tied to a global option to turn all cursor blinking on or off.

Well, I recently installed Mandriva 2009 and guess what…the cursor still blinks and there is still no option to turn it off. However, I was able to find a way:

  • Run gconf-editor (you can install it with sudo urpmi gconf-editor)
  • Navigate to /apps/gnome-terminal/profiles/Default/
  • Set the key “cursor_blink_mode” to off (You can add the key if needed by right-clicking and selecting “New Key”)

Now I get to use the Gnome terminal (my favorite, for some reason) and not have to see that horribly blinking cursor. Yay.


I made a software release

The first release of the Kingdoms of Ahln MUD Server (kams) is available over here.


Bus Television

I had this idea that it might be fun to watch TV shows or something on my little phone while riding the bus. It doesn’t have a typical 1/8” jack, though, so I had to do some spelunking and find the stereo earphones that came with the phone. Interestingly, they use the mini-USB connection. Kind of odd. But, amazingly, they sound great.

However, they look goofy. If you look at this picture (HTC makes the Dash) you can see that one earphone has a longer wire than the other. This makes the volume controller/microphone hang straight down from the ear to just below the collar bone while the other earphone stretches to the other ear. This makes it oddly unbalanced, annoying, and rather silly. I have to assume its because of the microphone needing to be near the face, otherwise it is completely ridiculous.

The other issue was finding a media player for those videos made for the iPod which are readily available. I know from previous research that TCPMP is considered the best free one (it has now been made into a commercial product as well). However, a few releases ago, they took out the AAC audio codec which is typically used for iPodish videos. Fortunately, some kind souls have provided the plugin here which seems to work fine with the 0.72beta version of TCPMP. Sweet. Now to find some good videos to watch…

Waaaay later update: My lovely and insightful girlfriend has suggested the earphones be worn such that they are in the back rather than the front. This is a big improvement.


Comments

You know have the ability to share your thoughtful insights on my clever and informative blog posts. Of course, if you were reading them through Facebook that probably wasn’t really a huge concern in the first place…

I wasn’t really planning on adding comments any time soon, but I happened across this Disqus thing which manages comment systems for you. You can add it to any webpage (which is good, because how many people have heard of Ozimodo, much less attempt to support it?) and it takes care of pretty much everything. Kind of neat.


Updates and the Horizon

Well, the conference paper that has been delayed again and again since the beginning of this year has finally been submitted to WICON so I feel a sudden sense of relief and release.

A meeting with my advisor today set out a fairly ambitious (I think) schedule for my next projects, but I am excited to get started on it, though that may just be because it is something new.

In celebration, Kingdoms of Ahln now has its own little server, meaning it is actually accessible to people other than myself. I plan to be putting a lot of time into it in the remaining summertime. I’ve had a lot of ideas bouncing around in my little head, but they are pretty worthless if they stay there!

It’s also time to finally start working on my mom’s website for her new independent practice, which I am sure she will appreciate.

And what about Pi, No Forks and Black Orange? Believe it or not, I do have some song things kicking around, but I have not had the time nor energy to record them. But maybe I will now. My instruments and recording stuff look sad and lonely.

I’m pretty much done with Sqwee for now, I think. I still use it, but haven’t had any burning desire to improve it or add any new features. Of course, maybe if other people used it and made suggestions…

One other thing I’m planning is maybe adding some way of leaving comments on this blogatron…though probably nobody would. Hrm…


Tiny App Launcher

Story

I just upgraded my lab desktop to Mandriva 2008.1. As usual, my first action was to install Xfce. That all worked well until I hit my usual Alt+F2 to launch a program. Nothing happened. I tried again. Still nothing. So I checked out the keyboard shortcuts, thinking they might be messed up. After actually finding where Alt+F2 gets set (there are a few different places in Xfce where keybindings are created), I saw it was indeed set up to run xfrun4, Xfce’s little run dialog.

I headed to the console (another aggravation: I am used to using gnome-terminal for my console, because I like its tabs and general feel. But it is way too slow for some reason and, even more importantly, I cannot figure out how to make the cursor stop blinking. It drives me nuts) and ran xfrun4 from there. Result: segfault

After poking around to see if there are any other little things like xfrun4 (something I have done before, actually), I gave up and wrote my own.

Requirements

Code
#!/bin/env ruby
require "rubygems"
require "zerenity/entry"
require "zerenity/warning"

loop do
        begin
                program = Zerenity.Entry(:title => "Run")
                if program
                        exec program
                end
                break
        rescue Interrupt
                break
        rescue Errno::ENOENT
                Zerenity.Warning(:text => "Program not found.",
                                 :title => "Error")
        rescue Exception => e
                Zerenity.Warning(:text => e.inspect, :title => "Error")
        end
end

Thrilling Conclusion

I dropped this in a file in /usr/bin/ and changed the keybinding…and that’s it. Works well enough, though it would be nice to have autocomplete/history stuff. But Zerenity does not have that (yet).


Sqwee and Unicode

As someone quite correctly pointed out, Sqwee wasn’t supporting Unicode very well. In fact, not really at all. You could put it in, but then things got weird. You might not think this would affect me much (I am generally a pretty ASCII kind of guy), but what happens when I want to do a little mathematical notation? Perhaps I need to write down {x, y} ∪ {z, y} for some reason. That would make Sqwee mildly blow up.

So I tentatively started poking into the Unicode world, expecting at any moment to have a dragon fry me to a crisp or to fall into some large crevasse. Interestingly, neither happened, but it was a little bit of a journey.

First, I found out all I needed to do was add a nice little meta-tag:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

Simple enough, right? I tried it. Didn’t help a bit. Manually switching the encoding (in Firefox) did work, though. After examining the headers using Live Headers, it was clear the content type was still being sent as iso-8895-1.

I figured this was due to the Lighttpd webserver not setting the content type correctly, so I went about trying to change that. I thought it would be possible to change it in the mimetypes:

mimetype.assign             = (
  ".html" => "text/html; content-type: utf-8" 
)

I saw this suggested somewhere, but it didn’t help.

Then I read that in Prototype Unicode doesn’t work with “get” and only with “post”, so I tried that:

 new Ajax.Updater("main", "index.rhtml", {
           method: "post",
           //...
        });

But it didn’t help either!

At this point I was getting somewhat frustrated, but then I remembered that eruby generates its own headers. Perhaps that was the problem?

Indeed it was! Fortunately, it is possible to set the content type via a commandline switch:
usage: ./eruby [switches] [inputfile]

  -d, --debug           set debugging flags (set $DEBUG to true)
  -K[kcode]             specifies KANJI (Japanese) code-set
  -M[mode]              specifies runtime mode
                          f: filter mode
                          c: CGI mode
                          n: NPH-CGI mode
  -C [charset]          specifies charset parameter for Content-Type
  -n, --noheader        disables CGI header output
  -v, --verbose         enables verbose mode
  --version             print version information and exit
Now I was in business! I went ahead and changed the Lighttpd config file to add in the appropriate switches:

cgi.assign = (".rhtml" => "/home/justin/sqwee/bin/eruby -Ku -C utf-8")
Unfortunately, this doesn’t work at all, because Lighttpd uses stat to check if the specified program exists and the options mess it up. To work around this, I needed to create a little script to launch eruby with the appropriate options:

#!/bin/env ruby
require 'pathname'
exec("#{Pathname.new(__FILE__).dirname}/eruby -KU -C utf-8 #{ARGV.join(' ')}")

That worked perfectly, and suddenly Sqwee had Unicode! That means time for a new release.


More Sqwee

Yes, I’m going talk more about Sqwee. I think it’s mostly because I’m excited about writing software with real version numbers… just kidding.

I’m still working on a good description of it. It’s incredibly simple stuff, but kind of hard to explain. It’s like a wiki, without lots of revisions and multiple users. So it’s like a personal wiki. But it is oriented towards being quick to install and quick to use, while retaining the flexibility for people to use it as they like. That’s why I sort of have the ‘prepackaged’ and ‘no frills’ versions, for running on a desktop and a shared server, respectively.

Anyways, enough blabbing about that stuff. I have been using Sqwee to take notes for a couple weeks now, and it actually works pretty well. But I noticed a couple of things that bugged me quite a bit:

First, if you are editing a page (taking notes) and you want to save it, but keep editing, you have to click ‘save’ and then ‘edit’ again. So I added the ‘quick save’ feature which will save the page but keep you in editing mode.

But then…how do you know it has really saved it and there wasn’t some problem? Or maybe it takes a long time to save or load a page…it would be nice to know when that kind of thing is “working on it” and when it has failed. So what I do now is have the button you press “gray out” while it is work in, then come back when it is complete. It works well when things are slow, but isn’t annoying when they are fast.

Anyhow, the point is that version 0.2.1 is out and I’m excited about the changes. Which, I forgot to mention, include the ability to search.


I don’t know why this matters and stuff

But I just realized that the three main computers I use (home desktop, laptop, lab desktop) all have different layouts. I use Xfce for my window manager, which (by default) has two panels: one is sort of a taskbar/system tray (like MS Windows) and the other is a launcher bar (like OS X).

At home, I have the launcher bar on the left, with auto hide, and the task bar across the top (and gkrellm on the top right). But on my laptop, there is a lot less screen space, so I only have the taskbar, which is stretched across the bottom and auto hides. In the lab, I have a bigger screen, but I basicly only use three applications: Firefox, Thunderbird, and a terminal. So I just have the taskbar across the top with a few buttons for launching programs. I don’t have any menus set up, because I pretty much launch all programs (besides those mentioned above) with Alt-F2 (run program) or from a terminal. If I get desparate, Xfce let’s me access a menu from right-clicking the desktop. And that’s it…

On a totally different note, I decided to start taking notes on my laptop this quarter to make them easier to study and search later. So, I went looking for a good note-taking program. The good news is that other people have gone on the same search. I looked at a few (Basket is really cool) before remembering that I have Sqwee and I specifically mention in the description that it can be used for note taking…oops. So I tried it out…it works pretty well, actually. Nice and simple. But I did find a problem with ‘special’ characters. I wanted to add in some ∩ and ⊆ kind of stuff, which you can do (fairly) easily by just using HTML. Strangely, that works fine, until you edit and then re-save the page. When you edit it (at least in Firefox) the characters are no longer displayed as HTML entities (&cap;) but as the actual characters (∩). That’s pretty cool, but then when you save the page the get manged into ASCII or something. Kind of annoying…I guess I should fix that.

I don’t know why anyone would need to know the preceding, but I felt like sharing.