Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

robin (1821)

robin
  (email not shown publicly)
about:blank

Journal of robin (1821)

Saturday August 04, 2001
09:35 AM

All hail Ann Barcomb

[ #609 ]

The conference is nearly over. The only event that's left is a rather chaotic auction and raffle, which is going on now. I haven't won anything :)

It's been a wonderful conference, full of ideas and enthusiasm (as well as some fun nights out).

Ann Barcomb has been the main organising force behind the conference, striding purposefully around the venue organising things. And somehow, in between all this, she's found the time to cook delicious vegan lunches for me of ever-increasing size and complexity. I think everyone else was a little envious, and Ann has my everlasting gratitude.

07:51 AM

lvalue subroutines made easy

[ #605 ]

I've just uploaded Want 0.04 to CPAN. The big news is that I've added what I call ASSIGN context.

It means that you can write clever lvalue subroutines without having to do a lot of tie magic. Here's an example:

sub backstr :lvalue {
    if (want(qw'LVALUE ASSIGN')) {
        my ($a) = want('ASSIGN');
        $_[0] = reverse $a;
         return undef;
    }
    elsif (want('RVALUE')) {
        my $t = scalar reverse $_[0];
    }
    else {
         carp("Not in ASSIGN context");
    }
}

print "foo -> ", backstr("foo"), "\n"; # foo -> oof
backstr(my $robin) = "nibor";
print "\$robin is now $robin\n";       # $robin is now robin

That's like the reverse function, except that you can assign to it.

I've just come out of Philippe Bruhat's amazing talk, in which he explained some obfuscated programs (including Erudil's camel code, and Philippe's own bilingual Perl/Postscript program). It's delightful to meet such people.

Friday August 03, 2001
07:57 AM

YAPC::Europe

[ #584 ]

I'm in YAPC::Europe, listening to Schwern's talk about CPANTS

Remember the Johnson-Trotter algorithm? I've been thinking about other similar algorithms. Here is a graph of the permutations of four elements ABCD, connecting the permutations which differ by a transposition of the first element with some other. Is there a general algorithm which will find a Hamiltonian path round a graph like that one? (I think so, though it's not as efficient as Johnson-Trotter. I'll put code here if/when I write it.)

I've been hacking on Want, and I've nearly finished the next version (0.04) - it has a new mechanism which makes writing lvalue subroutines really easy. I'm quite excited about it.

This morning I gave my Mutagenic modules talk, which went down pretty well. I think I lost a lot of people towards the end, when I started to talk about Perl internals a bit. Maybe I need to tone that down a little.

Friday July 27, 2001
04:10 PM

Johnson-Trotter

[ #517 ]
# A non-recursive implementation of the Johnson-Trotter permutation algorithm.
#
# The easiest way to understand the code is to stare at the output:
# it's pretty easy to see what's happening, and when you've seen that,
# think about how you'd implement it. You should end up with something
# similar to what's here.
#
# 2001-07-27 robin@cpan.org

use strict;
my @array = (qw'a b c X');

my @p = (0..$#array);    # Start at the end...
my @d = (-1) x @array;    # ...going left

sub next_perm {
    my ($l, $i) = (0, $#p);

    while ($i > 0
      && ( ($p[$i] == 0 && $d[$i] < 0)
        || ($p[$i] == $i && $d[$i] > 0)) )
    {
        ++$l if $p[$i] == 0;
        $d[$i] = -$d[$i];
        -- $i;
    }

    my $p_l = $p[$i]+$l;   my $p_l_d = $p_l + $d[$i];
    $p[$i] += $d[$i];

    @array[$p_l, $p_l_d] = @array[$p_l_d, $p_l];
}

for(1..25) {
    print "@array\n";
    next_perm();
}
Thursday July 26, 2001
10:06 AM

Oo welcome. Oo vudge welcome.

[ #505 ]
I finally have my own journal. I'll use it to make occasional notes on Perl things that I'm working on.

Yesterday I released Want 0.03. It's my attempt to implement most of RFC 21 for Perl 5, along with any other related features which seem cool or useful.

Recently I discovered the Johnson-Trotter algorithm for generating all the permutations of a list. It's a cool algorithm which goes from one permutation to the next by swapping a single pair of adjacent elements, mostly in constant time. I might put a bit of code here to illustrate how it works.