Older blog entries for kwa (starting at number 7)

Fun with Lisp on Python

I’ve been hacking on a useless little project lately. My friend Brandon and I have been toying with the idea of designing a new programming language over the last couple of years. We are both compiler nerds, and many of our conversations usually lead to to a discussion about why this feature is great and why that language
sucks.

I’m a pretty big Python fan, and have been using it for years. It is still my go-to language when I just want to get something done. Unfortunately, the more I learn about programming languages like Common Lisp, Scheme, Haskell, etc., the more I run up against the restrictions that Python has.

Unfortunately, many of these are deliberate. It seams that Guido and many others resist features like continuations, macros, non-broken lambdas and proper tail recursion because they like to think of Python as a single-paradigm language. Adding these features means that some Python code could seem foreign or unfamiliar for some programmers.

I understand this argument, but on the other hand I find it extremely frustrating when I have an elegant, easy to understand solution to a problem that I just can’t use because of a seemingly arbitrary restriction.

So I thought I would kill two birds with one stone. I could start designing a language for fun (not profit :-)), and when I am ready to write the compiler, I can just emit Python bytecodes, so that I will have a huge set of libraries to experiment with, and have something usable right away.

This turned out to be extremely easy. Within a few days I had a working compiler that was near feature parity with Python, and some nice features added on. It is still pretty basic at the moment, I don’t have many of the features implemented that I have planned. For now it’s just a simple lisp-like language with similar semantics to
Python. After a couple of afternoons work, I did a google search for similar projects, and it turns out that there are about 10 people that have done something similar. I don’t really care though, this is just for fun.

One of the decisions that I made early on is that Python’s modules are a good idea. I think the module and namespace semantics are extremely well thought out in Python, and have encouraged a lot of really great patterns and idioms. So this language is definitely going to mirror that behavior.

One of the things I struggled with was under what circumstances should I allow myself to add syntactic sugar. I’m usually not a fan of such features, but there is one case where I made a compromise, and that is accessing attributes of an object. I tried to avoid this for as long as I could, but I tended to write a lot of code like this:

(set (getattr (getattr someobject 'propertya) 'propertyb) value)

In this case, I ended up settling for:

(set someobject:propertya:propertyb value)

I’m not really satisfied with that at the moment, but at least it is about the only such compromise I’ve made.

Another thing that is pretty important to me is avoiding any special operators. This is something that really bugs me about common lisp, I hate having to write code like this:

(reduce #'(lambda (x y) (* x y)) '(1 2 3))

Why can’t ‘*’ be a function? Scheme gets this right in most cases, but there are still around 10 special operators. I want zero special operators, or at least as few as possible. I ended up accomplishing this by allowing special operators to behave like functions in contexts where that made sense, and otherwise treating them like special operators. For example, the situations below would generate very different code:

(reduce * '(1 2 3))

This would simply map to a built in function for multiplication, that is only used when ‘*’ is used as a symbol. Otherwise:

(* 1 2)

This emits a normal BINARY_MULTIPLY instruction. This way it appears to have no special operators, but the code that is generated is as efficient as possible. I’ve tried to do this where ever I can.

At this point, it is possible to write just about any program you would write with Python, with a few minor exceptions that would be trivial to fix. Here is a simple pygtk program:

(import gtk)
(set my-window (gtk:Window))
(my-window:set_title "Hello, World!")
(my-window:connect "delete-event"
                   (lambda (w event)
                     (println "Goodbye, world!")
                     (gtk:main_quit)))
(my-window:show)
(gtk:main)

It really is remarkable how much Python resembles a Lisp internally. In some cases, what I thought would take days of hacking turned out to only take 1/2 hour. An example was loops. I wanted to implement something like the Common Lisp loop macro, only not as terrifying :-). It turns out that the behavior isn’t much different from Python list comprehensions, so implementing something like this was pretty trivial:

(loop
  for x in (range 10)
  for y in (range 10 20)
  if (not (= x y))
  collect (x y))

Although in the end I simplified loop a great deal, it was fun to see it work with so little effort.

I don’t know if I will actually release this code. It isn’t really that useful, it’s just a fun little project to tinker with and an easy way to try out new experimental language features. But if you want to play with what I have now, you can get it from my Bazaar branch.

bzr branch http://codewalking.com/bzr/sketchy.dev

My plan is to continue experimenting with this, and eventually weed out all of the unnecessary features. At some point I imagine having something that would be worth rewriting, maybe targeting another VM with a JIT like the LLVM, the CLR or Java, or writing my own JIT (that would be fun!).

Syndicated 2008-03-23 01:24:29 from Code walking

GUADEC 2007 videos available


<p>Awesome, <a href="http://ftp.gnome.org/pub/GNOME/teams/guadec/2007/videos/">videos</a> from <a href="http://www.guadec.org">GUADEC</a> 2007 are <a href="http://ftp.gnome.org/pub/GNOME/teams/guadec/2007/videos/">available</a>! Guess I'm not going to get any sleep tonight. </p>

Syndicated 2007-12-07 11:12:16 from Codewalking.Com

28 May 2006 (updated 28 May 2006 at 22:49 UTC) »

Well, I spent most of my Saturday trying to figure out how to use the mono bindings for Avahi. They aren't that complicated, but no one has written any documentation yet. Today I've been experimenting with a Zeroconf plugin for beagled.

Currently beagled will publish its index, and will keep track of any remote indexes it finds in the log file. It's a start!

24 May 2006 (updated 24 May 2006 at 08:35 UTC) »

Holy crap!!! My extremely half-ass summer of code proposal was accepted?!? I have to say that I'm a little surprised. I submitted a proposal to the Beagle project entitled Networked Searches in Beagle. Here are the details:

Summary

I would lovepost to extend Beagle to use Avahi to advertise beagle running on a workstation, and allow other computers to search its indexes in a fashion similar to music sharing in Rhythmbox.

Deliverables

  • Extension of Beagle's XML-RPC system for secure communication on a local area network.
  • Automagic Beagle service discovery via Avahi.
  • Integration of Remote Searches into Holmes.

Timeline

  • June 26, 2006:
    Avahi service discovery implementation complete. Design completed for remote message passing interface, and partial implementation.
  • August 21, 2006
    Message passing interface completed. Holmes extended to perform remote queries and fetch data from remote hosts.

Authentication and Setup

Authentication would be comprised of a cryptographic challenge/response system using pass-phrases and keys. Once two nodes have been paired up, they will automatically talk to one another when they are on the same network. A "Sharing" or "Network" tab could be added to beagle-settings, which would allow the user to enable searching on the local network, and sharing local indexes with other computers.

When beagled finds another host sharing its indexes, the user would be notified, and given the opportunity to perform an initial authentication. If the automatic notification is too annoying, then the user could have some means of finding other computers to pair up with. Beagle daemons on remote machines will communicate via XML-RPC.

Searching

When searching in beagle-search, a query is sent to beagled, and beagled forwards the search to any hosts on the network that have been authenticated in the past and are currently available with shared indexes. Any nodes that require no authentication will automatically be searched.

For live queries, any nodes that leave the network or are no longer available will be removed from the results. Any new node that becomes available during a live query will be sent the query and any results will reported. Remote Beagle daemons will treat these live queries just like a local live query on that machine, and will send new results to the node that made the initial query until the remote live query ends, or the node that made the initial query becomes unavailable.

User Interface

Any remote hits will be displayed in such a way to indicate that they are from a remote machine. They can also be hidden by a disclosure triangle, and will only be shown if there are available results. For example:

Double clicking on a hit from another computer might be tricky. Maybe using HTTP to download the file from one host to another. The file could either be copied to a /tmp directory, showing some progress dialog until it is copied and then opened, or just using GnomeVFS. Itwould also be useful if the user could also drag and drop any remoteresults to a nautilus window or the desktop, which would copy it tothe local disk.

Non-file Data

The original webservices implementation for Beagle only handled file queries. It would be interesting to find a way to handle remote chatlogs, webpages and emails.

Me

I am finishing my third year of undergraduate studies at California State University, Sacramento, where I am majoring in Computer Science. I've been using GNU/Linux on the Desktop since 1999, and am passionate about free software. See my resume for more information.

As for my .NET experience, I have been using Mono since its 1.0-beta release, have been loving it ever since. I used Mono to develop several in-house Gtk# applications at work, and a charity raffle system for a large annual charity event in California.

As a casual GNOME contributor, and a Beagle user since 0.0.[89] ish, I would love to have the opportunity to hack on Beaglefull time this summer. Beagle is one of the most interesting components of the GNOME Desktop, and I would love nothing more than to help make it more useful for the community.

Congratulations to all of you other students out there who were also accepted, and thank you so much Google for working so hard to make this happen. And most of all, thank you Joe Shaw and any other mentors for the Beagle project for giving my proposal a high ranking.

2 Sep 2005 (updated 31 May 2006 at 02:03 UTC) »

Oops

24 Aug 2005 (updated 25 Aug 2005 at 07:36 UTC) »

Various things
This makes me sick to my stomach.

Found this very amusing quiz on p.g.o. I did recognize a few, but only got 6 out of 10 correct. Apparently, I should "avoid a career in either law enforcement or IT recruitment."

And finally, Chris Dibona has posted some awesome photos taken at Foo Camp with a high speed camera. They feature attendees, including Gnome Hacker Nat Friedmen, popping balloons.

Google Talk
While I am extremely pleased that a corporation as powerful as Google is supporting a free, open standard like Jabber, I'm sort of annoyed that their new Jabber service doesn't allow traffic from other Jabber servers. I have had a jabber id (kwa@jabber.org) for quite some time, and was hoping that this announcement would inspire a good number of my friends who use Gmail to switch to Jabber. It seems that this will change. The sooner, the better.

Photos
I finally got around to posting the pictures from our road trip to Vancouver a couple of months ago. The latest version of F-Spot is broken in the Flickr department, so I used F-Spot to generate a static HTML web gallery. Nothing on bugzilla or the mailing list. I'll have to look into it.

Alright, I'm pissed! I just started to upload some files, mostly python scripts and various other things so anyone who is interested can download and use them. Since CSUS provides web hosting for their students, I decided to host these files there. So far, everything is fine.

About 1/2 hour ago, I was chatting with a friend of mine named Jason Ralphs. I tried to show him the blogrip.py script that I had just uploaded, and we both got 404 errors. Startled and confused, I went to upload the files again thinking that I had just forgotten to do so. But of course, they were still there.

Unfortunately, my university uses IIS on a Windows server to serve its webpages. After some experimentation, I realized that IIS would only serve files that matched a registered mimetype on the server itself. So when you try to download a file like a python script, a c header file or a tarball, it just pretends that the file isn't there. BRILLIANT!!! I'm sending an angry email right now. Of course, it wouln't solve anything, but I'm just curious to see what those helpdesk monkeys have to say.

19 Aug 2005 (updated 19 Aug 2005 at 20:30 UTC) »

First post to my new advogato web log.

Well, I'm about to start class at CSUS in just over a week. I'm looking forward taking some more computer science courses after a year long hiatus. I've spent the last year finishing my lower division general education before transfering to the university.

Edd Dumbill released monopod-0.4 recently, and I don't like the fifo "Recent podcasts" playlist it creates on my iPod. When I find the time I'm going to modify it to create playlist for each podcast, so that...

  1. Latest shows from each feed are easier to find and ...

  2. I don't just end up with nothing but 10 episodes of Science Friday.

I must listen to podcasts much differently than Edd. I am subscribed to over 20 feeds with weekly or fortnightly radio shows, and I sometimes listen to 4 or 5 in one day. Some of the shows I almost never listen to, but I like to keep around just in case I get stuck somewhere with nothing to do. If I only have 10 podcasts, then I'll run out of things to listen to.

I think there should be a gconf key, and eventually a preference setting to choose the prefered way to synchronize with your ipod. The possible modes of operation would be:

  1. "Recent N podcasts" playlist
  2. One Playlist for each feed
  3. both simultanously
We'll see what Edd thinks.

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!