Slash Boxes
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)

  (email not shown publicly)

Journal of robin (1821)

Saturday May 25, 2002
09:57 AM

You know you're starting to think in O'Caml when...

[ #5214 ]
You write Perl code like this:

sub gron {
  my ($f, $total, $width) = @_;
  my $veet;
  $veet = sub {
    my ($partial, $subtotal, $n) = @_;
    my $rem = $total - $subtotal;
    if ($n+1 == $width) {
      $f->($rem, @$partial);
    else {
      $veet->([$_, @$partial], $subtotal+$_, $n+1) for 0..$rem;
  $veet->([], 0, 0);

gron(sub {print($_ ? $_ : " ") for @_; print "\n"}, 3, 27);

I'm fairly sure that the idea of using a recursive closure in Perl has never crossed my mind before. Notice the disguised conses as well :-)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.