Categories
Posts in this category
- A shiny perl6.org site
- Creating an entry point for newcomers
- Sprixel, a 6 compiler powered by JavaScript
- Another perl6.org iteration
- Blackjack and Perl 6
- Why I commit Crud to the Perl 6 Test Suite
- Custom operators in Rakudo
- Defined Behaviour with Undefined Values
- Dissecting the "Starry obfu"
- Perl 6: Failing Softly with Unthrown Exceptions
- The first Perl 6 module on CPAN
- Google Summer of Code Mentor Recap
- Building a Huffman Tree With Rakudo
- Immutable Sigils and Context
- Is Perl 6 really Perl?
- Perl 6: Lost in Wonderland
- Lots of momentum in the Perl 6 community
- Musing and the future of feather and the Pugs repository
- Musings on Rakudo's spectest chart
- My first executable from Perl 6
- Trying to implement new operators - failed
- Let's build an object
- Perl 6 is optimized for fun
- How to get a parse tree for a Perl 6 Program
- Perl 6 in 2009
- Perl 6 ticket life cycle
- The Perl 6 Advent Calendar
- How to Plot a Segment of a Circle with SVG
- Publicity for Perl 6
- Rakudo architectural overview
- Rakudo Rocks
- Rakudo "star" announced
- Rakudo's rough edges
- Rats and other pets
- Releasing Rakudo made easy
- Set Phasers to Stun!
- Starry Perl 6 obfu
- Recent Perl 6 Developments August 2008
- Strings and Buffers
- Subroutines vs. Methods - Differences and Commonalities
- A SVG plotting adventure
- A Syntax Highlighter for Perl 6
- Test Suite Reorganization: How to move tests
- The Happiness of Design Convergence
- Perl 6 Tidings from September and October 2008
- Perl 6 Tidings for November 2008
- Perl 6 Tidings from December 2008
- Perl 6 Tidings from January 2009
- Perl 6 Tidings from February 2009
- Perl 6 Tidings from March 2009
- Perl 6 Tidings from April 2009
- Perl 6 Tidings from May 2009
- Perl 6 Tidings from May 2009 (second iteration)
- Perl 6 Tidings from June 2009
- Perl 6 Tidings from August 2009
- Perl 6 Tidings from October 2009
- Timeline for a syntax change in Perl 6
- Visualizing match trees
- We write a Perl 6 book for you
- When we reach 100% we did something wrong
- Where Rakudo Lives Now
- Why was the Perl 6 Advent Calendar such a Success?
- What you can write in Perl 6 today
- Why you don't need the Y combinator in Perl 6
Sun, 21 Jun 2009
Trying to implement new operators - failed
Permanent link
This isn't a success story - it's only almost a success story.
On perlmonks.org we had a Golf challenge (ie writing code in as little characters as possible): write an implementation of the Euclidian algorithm in Perl 6.
I proposed a solution
which I liked very much, but which didn't work in Rakudo yet, because it
used the series operator infix:<...> (yes, three literal
dots) which isn't yet implemented in Rakudo. D'oh!.
I like Perl 6 discussions on Perlmonks, but every solution that shows a NYI-feature encourages the "Perl 6 is vapor-ware" thoughts and comments. So I decided to make it work, and decided to JFDI and implement the missing operator.
In general implementing a new operator in Rakudo is not much harder than implementing a function: all you have to do more is to add it to src/parser/grammar-oper.pg including precedence and associativity (both of which can be found in the spec.
For quite a while now built-in functions and methods can be written in Perl 6 now, so I also decided to write the new operator in Perl 6. Since lazy lists aren't implemented yet, I decided not to care about the lazy version, and did the eager version instead. This is what my code looked like:
multi sub infix:<...> (@lhs, Code $generator) { my $c = $generator.count; if $c > @lhs { fail 'the closure wants more parameters than given on the LHS'; } my @result = @lhs; my @r; # XXX work around http://rt.perl.org/rt3/Ticket/Display.html?id=66824 # this is a bit ugly.. since @a[1..1] returns a single item and not # an array, |@result[$one-item-range] throws the error # "argument doesn't array" while @r = $generator(|@(@result[*-$c..*-1])) { @result.push: @r; } return @result; }
This works... partly. It works only in the file it is defined in, not if it's defined in the setting library.
So to summarize: I have an implementation ready, but due to Rakudo bugs it can't go into mainstream Rakudo right now. JFDI, partly failed.
Comments / Trackbacks:
Trackback URL:
/blog-en/perl-6/new-operators-failed.trackback
moritz wrote
Fixed
In the mean time Patrick has fixed the issues, so we now have a (partial) implementation of infix:<...> in Rakudo.
Write a comment
The comments on this blog post have been disabled; the comment form below will not work.