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 ]

autrijus (1505)

autrijus
  (email not shown publicly)
http://pugs.blogs.com/

Journal of autrijus (1505)

Friday May 20, 2005
03:23 PM

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

[ #24799 ]

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:

<iblech> Yeah, I start to grok Haskell :)
<autrijus> 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. :-)

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