Day 107: Inline::Pugs! Infix operator!

autrijus on 2005-05-18T23:25:55

An one-hour hack of mine proved fruitful. Below is a Perl 5 script, calling into Perl 6 functions:

#!/usr/bin/perl
use Inline Pugs => '
    sub postfix: { [*] 1..$_ }
    sub sum_factorial { [+] 0..$_! }
';
print sum_factorial(3); # 21

The implementation is in the Pugs tree as lib/Inline/Pugs.pm; you wil need Inline.pm from CPAN to run the example above.

Another big news is that iblech hacked in user-defined infix operators. He started a fp.pm to showcase all the APLish things we can do with infix Unicode OPs. But my favourite sickitude is this faked list comprehension:

# This prints "3 9 15 21 27"
say [ {$_ * 3} | $_ <- [1 .. 10],:{ $_ % 2 } ]

# ...and here are the magic bits...
sub infix:«|» ($x, $y) { $x }
sub infix:«,:» ($x, &y) { [grep &y, $x] }
sub infix:«<-» (&x, @y) { map &x, @y }

mugwump and iblech applied this to Set.pm, which overloads various ASCII operators, as well as the ∩, ∪ and ∋ Unicode operators.

Seeing how PA02 has been delayed (again), nothingmuch interviewed me for a couple hours about Pugs interals, so he can start writing it. We covered Parser, Eval, ITypes and some Object core today -- more to follow later!

iblech also hacked in preliminary support for auto-generating [...] (reduce metaoperators); support for »...« (hyperoperators) should be coming soon as well.

putter reported that external PGE's match fails when the string to match contain a newline; it turns out to be a problem involving Parrot's line buffering. I fixed it using a hand-rolled escape scheme; however, I learned from matt in #parrot that stdin."setbuf"(0) will probably also fix it.

Corion reported that Win32's system($cmd, @args) quoting had similar problems with Perl 5; he committed some basic test for it and starts thinking of a better plan to fix it.

bsmith discovered a pugsbug that parses (1) { 2 } as (1).{2}, and wrote tests for it.

Stevan and mugwump continued MetaModel work, adding findMethod, invokeMethod, isPropertySupported and various other features. Most of them even comes with tests!

ninereasons fiddled with motd.p6 to generate a more sentence-like fragment, and tidied up its code.

theorbtwo committing another 100ish lines of changes, adding signatures and Haddocks to many Pugs internal modules.

putter did tons of work on the Rules tests imported from Perl6::Rules, cleaning up obsolete syntax and ensure that things pass both for external and embedded Parrot. Lots of bugs were shaken out and fixed.

I think that's all for today. See you tomorrow!