Archive for April, 2010

Andy Wingo: recent developments in Guile

2010-04-19

I watched a talk by Andy Wingo recently: recent developments in Guile. GNU Guile is a Scheme implementation, and a library providing an extension language for applications. Guile is actively developed, and promises some exciting stuff in upcoming releases, which is why I took these notes and publish them here–read on.

Andy starts by noting that Guile is different things to different people:

  • A GNU language, with bindings for many components of the GNU system and under LGPL 3.
  • A Scheme implementation, supporting R5RS and part of R6RS, plus other goodies: modules (not the R6RS ones), hygienic macros, the CLOS-like object system Goops with transparent integration with GLib’s gobject, Posix interface, and Unicode support.
  • An extension language for applications, like the Gimp.
  • A part of the GNU system (that we are making, even if we don’t know yet how it will look like).

Andy sees Guile’s perception among developers as its main challenge currently. It’s seen as being slow, although it’s generally faster than Python. But there are also opportunities for its perception: its multilingual vision and support–its next release will support ECMAScript besides Scheme, and Emacs Lisp is coming–, and the GNU brand.

Some technical notes

It uses the Boehm-Weiser garbage collector now, which is fast and reliable.

There are ten committers and monthly releases. This is after the project emerged from a long drought in 2000-2007.

Guile has a VM, and a native compiler is coming. Also: JavaScript support, ELisp coming!

It has really good Emacs integration now with Geiser.

There was also a small remark about licensing. Readline and Guile are not quite license-compatible, which makes using the REPL a pain. This sparked a longish discussion–kinda what you expect from a GNU developers meeting :-)

Spreading the Emacs nature

And now, the meat of the talk: spreading the Emacs nature, to emacsify the GNU system. Yes, that sounds like it!

The upcoming Guile 2.0 (or maybe 2.1?) will have full ELisp support, at the moment about equally fast than Emacs’ own, but it will be much faster. It will also have native compilation for even more performance.

Besides performance, it will have much more to offer:

  • native threads,
  • a clear FFI,
  • modules,
  • other languages, as described above,
  • the Goops object system,
  • lots of library bindings – Emacs-Gnome integration would easily be possible, for instance.

Andy’s plan is to replace Emacs’ Lisp engine with Guile. The rest stays unchanged, existing ELisp code will run as-is. Then no form of coercion should be necessary to get people to start writing their Emacs code in Guile languages. The timeframe is 18-30 months from now–looks like a developer release is not too far off!

Mocking LWP::UserAgent with POST redirection

2010-04-11

To test the ubiquitous (and awesome) LWP::UserAgent module, I use Test::Mock::LWP. It works as advertised, with minimal code. However, I still found myself writing a little plumbing. Here are two code snippets that I use when using Test::Mock::LWP.

First, a way of mocking code using LWP::UserAgent’s requests_redirectable array, as in


sub _new_agent {
    my $agent = LWP::UserAgent->new;
    push @{$agent->requests_redirectable}, 'POST';
    return $agent;
} 

This won’t work with vanilla Test::Mock::LWP, as requests_redirectable is not a method and therefore cannot be mocked – a small flaw in UserAgent’s API. To circumvent the problem, mock your own UserAgent creation sub (you did encapsulate that, didn’t you):


use Test::MockObject;

# In addition to Test::Mock::LWP, we also need to mock our own
# wrapper for LWP::UserAgent->new, as it needs UserAgent's
# requests_redirectable array and the mock doesn't have that.
Test::MockObject->new()
  ->fake_module('My::Foo',
                '_new_agent' => sub { return LWP::UserAgent->new; }
               );

Second, just a tiny sub to make things nicer, IMHO: it provides a clean abstraction to get the latest requested URL. It’s useful if that’s all you want to test. This makes tests nicer to read and isolates them from the mocking module. It also encapsulates the magic index we need to get the requested URL from the request header array. The index is 2 here, this works for code making requests using HTTP::Request::Common. It’s probably different if you use HTTP::Request directly, but the test runner’s expected/actual output will quickly show you where the URL hides.

sub latest_requested_url {
    return scalar $Mock_request->new_args()->[2];
}

Interesting Perl 5 modules

2010-04-08

In my journey into Perl this last year or so I’ve naturally done a lot of research on available modules. After all, the huge variety of CPAN is one of Perl’s strongest points. I journaled a few modules that struck me as particularly interesting, so why not merge these notes and links and publish them for others finding their way in the modern Perl world.

PSGI/Plack

Superglue interface between perl web application frameworks and web servers, just like Perl is the duct tape of the internet.

Inspired by Python’s WSGI and Ruby’s Rack, this is the modern way of doing Perl web apps.

PSGI is a specification to decouple web server environments from web application framework code. [...] Web application developers (end users) are not supposed to run their web applications directly using the PSGI interface, but instead are encouraged to use frameworks that support PSGI, or use the helper implementations like Plack (more on that later).

A large number of HTTP servers support PSGI, so you’ll find anything from simple embedded solutions to non-blocking, asynchronous ones with Comet support.

Similarly, a large number of web frameworks have been built with support for the PSGI spec, again from the advanced and complex like Catalyst to the simple like Dancer. At first I wanted to show off some cool Perl web frameworks in this post, but there are so many nowadays that would deserve to be mentioned that I’ll just refer you to the PSGI/Plack site and let you pick whatever floats your boat.

AnyEvent

the DBI of event loop programming

AnyEvent lets you write event-based (callback-based) code without limiting you to a certain event loop. The event loop based nature of your module is transparent to the user. A large number of external loops are supported, among them Glib (for GTK/Gnome apps) and Qt.

There’s also POE with a very similar purpose. This post and its comments contain a lot of useful information and opinions to compare the two.

Dist::Zilla

distribution builder; installer not included!

Similar to many other modules, this one helps build distributions for upload to CPAN. However, it does not address installation of the module. Therefore, it can do powerful stuff, as it’s only run by developers and typically runs on a repository. It features a promising git integration module, for instance. Reviews are very favorable.

Data::Traverse

Callback-based depth-first traversal of Perl data structures

Data::Traverse exports a single function, traverse, which takes a BLOCK and a reference to a data structure containing arrays or hashes. [...] Data::Traverse performs a depth-first traversal of the structure and calls the code in the BLOCK for each scalar it finds.

Simple and useful.

Email::Stuff

A more casual approach to creating and sending Email:: emails

In a “Why use this?” section – a good idea – the author shows that using this module, you don’t need to know how to structure MIME messages, and the code is very short and clear.


Email::Stuff->to('Simon Cozens<simon@somewhere.jp>')
            ->from('Santa@northpole.org')
            ->text_body("You've been a good boy this year.")
            ->attach_file('choochoo.gif')
            ->send;

Weekly Links #2

2010-04-01

Conrad Barski and James Webb: Casting SPELs in Emacs Lisp

Conrad Barski’s awesome Lisp tutorial Casting SPELs is now also available in an Emacs Lisp version, edited by James Webb. Even if Emacs Lisp is certainly not the greatest Lisp dialect, it shouldn’t matter much for a beginner’s tutorial and it sure is nice to be able to evaluate everything right in your editor.

ars technica: Tentacular, tentacular!

Cthulhu plucked a manila folder from somewhere within the non-Euclidean geometry of his manbag and dropped it on my desk with a thud.

A geeky, hilarious choose-your-own-adventure story written by Cthulhu. What else could you want for your Easter weekend.


Follow

Get every new post delivered to your Inbox.