Day 109: Coroutines, gather/take, symbolic deref, use pugs!

autrijus on 2005-05-20T20:23:26

The Inline::Pugs hack inspired Ingy, so he implemented pugs.pm. To wit:

#!/usr/bin/perl
use pugs; # Here is some Perl 6 code...
sub postfix: { [*] 1..$_ }
sub sum_factorial { [+] 0..$_! }
no pugs; # Here is some Perl 5 code...
print sum_factorial(3); # 21

A highly experimental implementation of coroutines has landed to Pugs, with semantics loosely borrowed from Perl 5's Coro::Cont:

coro flip_flop { yield 1; yield 0 }
print flip_flop() while 1;

# Output:
# 101010101010....

Here is a more interesting example, courtesy of integral:

my @generators = map -> $N { coro { yield $_ for 0..$N } } 0..3;
say "{ map { $_() }, @generators }" for 0..3;

# Output:
# 0 0 0 0
# 0 1 1 1
# 0 0 2 2
# 0 1 0 3

As the coroutine design in Perl 6 had not been finalised, this is merely an experimental feature for people to play with; suggestions are most welcome -- see my p6c post for details.

Limbic_Region asks whether gather/take has been implemented. I said no, then promptly corrected myself 15 minutes later by implementing it. :-)

The Haskell-fu is really strong with iblech nowadays:

 Yeah, I start to grok Haskell :)
 iblech++ # demonstrating that the productivity is really not me, it's really Haskell :)
Among the usual influx of tests and work on the p6explain script, he also implemented:
  • min, max and uniq as described by Damian.
  • [.[]] and [.{}] for walking down a nested data structure by a list of keys.
  • [or], [err] and the rest of logical reduction metaoperators
  • Symbolic dereference: $::("foo").
  • [,] -- with two lines of code.

Colin Paul Adams has successfully embedded Parrot in his XSLT processor, although he ran into some problems more-or-less the same with Pugs/Parrot embedding; however, this time around I have the committer bit, so with Leo's guidance, I've checked in an implementation for the missing string_to_cstring API.

Colin also asked on p6c about how to embed Pugs into the XSLT processor; I regretfully told him that Pugs does not yet handle Perl 5 programs, but gave a few pointers that are hopefully useful.

  • mugwump and Stevan started porting Pugs to Perl 6, by translating its core types into its MetaModel counterparts.
  • duff and Aankhen worked on quickref/rules.
  • eric256 worked on examples demonstrating bitwise operators and .pick.
  • nothingmuch continued his work on PA02, and interviewed me about closure support in Pugs internals.

There's much more, but I need to sleep (a lot) now. :-)