May 2009 Archives

It’s time for me to praise one of the useful utilities that makes my everyday work just a little bit more pleasant: rlwrap.

rlwrap “wraps” other interactive programs, providing readline functionality for programs that don’t have it built in. For example, last week I had to repeatedly use ‘imtest’ and ‘cyradm’ while doing some exploration about IMAP. Neither of these tools supports readline, so I normally would be able to press ‘up’ to recall my last command, use ^W or ^U to clear parts of my command, or use ^R to search my history. This would be very frustrating.

So, here comes rlwrap. You use it just like sudo, prefixing it to the command you want to run, thus

imtest -u sweeks -a vmadmin -t '' -m plain localhost

becomes

rlwrap imtest -u sweeks -a vmadmin -t '' -m plain localhost

rlwrap even remembers command history on a per-command basis, so you can recall your interactive commands from previous sessions. This greatly eases debugging. rlwrap is a very valuable part of my toolkit. If this interests you, you can also enable filename tab-completion, or even custom wordlists for tab-completion of command-specific commands.

I mentioned this to my co-workers, and I was surprised to hear that none of them had ever heard of it before. What tools do you use that you take for granted that everybody knows about?

On Saturday, I wrote up a possible API for Parrot compilers to support loading libraries written in other languages and discussed some of the details with Jonathan++ and Allison++. It’s not perfect, and is missing a few parts, but should be extensible enough to support whatever else we need in the future. I still need to formalize it a bit and add it to the Parrot docs and the example language shell.

On Sunday, I implemented it on Rakudo (Perl 6) and Cardinal (Ruby; very incomplete).

This morning, after confirming the spec with pmicahud++, I merged the changes into Rakudo trunk.

The syntax for specifying the source language for Perl 6 is:

use Foo:lang<cardinal>;

I couldn’t quite figure out what an appropriate way to do this in Ruby would be, so I just added a function to cardinal:

foreign_load('perl6','Foo/Bar')

If you have a better suggestion for what it should look like in Ruby, please let me know! I don’t actually know much Ruby at all, so my Ruby compiler is fairly limited.

I’ll be adding support for this to pynie (Python) soon, and other languages after that.

Here’s a simple example of using a Perl library from Ruby:

[sweeks@kweh ~]$ cat Foo.pm
module Foo {
    sub greet($name) is export {
        say "Hello, $name!"
    }
}
[sweeks@kweh ~]$ cat perl6.rb
foreign_load 'perl6', 'Foo'
['Ruby', 'Perl', 'World'].each { |name| greet name }
[sweeks@kweh ~]$ cardinal perl6.rb
Hello, Ruby!
Hello, Perl!
Hello, World!

Here’s a similar example of using a Ruby library from Perl:

[sweeks@kweh ~]$ cat Foo.rb
module Foo
    def greet(name)
        puts "hello, " + name
    end
    def apply_people(cb)
        people = ['Dave', 'Bryan', 'Stuart', 'Dax']
        people.each { |name| cb(name) }
    end
end
[sweeks@kweh ~]$ cat ruby.pl
use Foo:lang<cardinal>;
greet("person $_") for 1..5;
apply_people( { say "hello from perl, $^name" } )
[sweeks@kweh ~]$ perl6 ruby.pl
hello, person 1
hello, person 2
hello, person 3
hello, person 4
hello, person 5
hello from perl, Dave
hello from perl, Bryan
hello from perl, Stuart
hello from perl, Dax

Thanks go to my employer (Guru Labs) for their support in my work on Rakudo and Parrot.

Rakudo is just starting to get support for adding custom operators to the grammar from user-level code. You can’t specify the precedence yet, but you can run the traditional examples:

multi sub infix:<±>(Int $a, Int $b) { return $a + $b | $a - $b }
multi sub postfix:<!>(Int $a where { $_ > 0 }) { return [*] 1..$a }

my $x = 5! ± 2;
say "hi dood" if $x > 121;
say "hello again" if $x < 119;

I was playing around today with defining operators for mathematical set operations (∩ ∪ ∖ ⊂ ⊃ ⊆ ⊇ etc.) and then decided that I wanted a fancy syntax for defining sets, so I added support to rakudo for circumfix operator definition, and i now have this running on rakudo:

say "subset" if ⦃ 1, 3, 5 ⦄ ⊆ ⦃ 1, 2, 3, 4, 5 ⦄;

Blog speed-run.

| 175 Comments | No TrackBacks

On Sunday, before I left for my flight, I saw masak chatting on IRC about his blog speed-run, which I later found described here. He set a time limit to see how quickly he could implement a basic blog app on the tools we've been building.

At the airport later that day, I had 20 minutes to wait before boarding my flight, so I thought I'd try the same thing. Omgblog is what I got done before I needed to board. I'll try to leave it running for a while. The source is in the usual place.

About this Archive

This page is an archive of entries from May 2009 listed from newest to oldest.

April 2009 is the previous archive.

Find recent content on the main index or look in the archives to find all content.

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.32-en