fREWdiculous!
10 Aug
Today we had our Dallas.p6m meeting, which was a lot of fun as usual. This meeting was especially interesting because Rakudo * was released since we last met. In the meeting I discussed my little project to port Log::Contextual to Perl 6. First off, here’s the code.
There are plenty of positives and negatives to Rakudo *. First the positives!
It’s pretty cool that the tests actually pass! Not all of them of course though…
People may not take this seriously, but . is better than ->. Seriously. Plus there are types etc.
So…. this may or may not be a feature. It works for the simple stuff. Is it as flexible as Sub::Exporter?
In Perl 5 if you want to define a private method you use _ as a prefix. First off that’s an idiom, not part of the language, yadda yadda yadda. More importantly, it’s not really private, just marked as “don’t use this.” With Perl 6 it’s (almost) truly private. Nice.
A lot of people are gonna hate this one; but it’s meant to solve the “print (5 + 6) * 12″ issue. It has a lot of other implications too, which again, are going to bother people. Now I can name a method log-debug instead of log_debug or lord forbid logDebug. Nice!
Arguably the best feature of Ruby. Perl 6 does it now. Neat!
This is hard for me. In Perl 6, a block (denoted “{ … }”) should take zero arguments unless you explicitly state otherwise (with $^a etc.) You may not notice that in most places, but Log::Contextual uses that kind of stuff constantly. I expected it to be like Method::Signatures::Simple which just sets values to undef if they are not passed. Anyway, I can live with this, it’s just different.
This is more like Javascript and Ruby, both of which I’ve used with joy, so I’m sure it will be fine. The gist of it is that when you do:
1 2 3 4 | sub foo (@bar, $baz) { ... } my @biff = 1,[2,3]; foo @biff; |
You will get an error because @biff binds to @bar and $bar is not set. If you want to use an array for arguments you have to do “foo |@biff”. Much nicer than javascript’s apply, and the same as Ruby’s *.
This is not surprising at all. Not even really a complaint, but must be noted. To run the entire testsuite for Perl 5 takes 1.5 seconds. To run a single test for the Perl 6 version it takes more than 10 seconds. I learned in the meeting that I could precompile my modules and save a lot of time; like, three orders of magnitude difference.
Again, this is expected. Still annoying. Features I miss are lack of temp (which Patrick pointed out that I can almost replace it with dynamic variables, and soon I will be able to all the way), lack of caller, and write access to the symbol table.
My main example is that in Perl 6 undef == Any(). Patrick explained it. It makes sense. It’s still weird.
I couldn’t figure out how to get Roles to work. I’m not really sure how it is supposed to work. Am I supposed to use the role in the class that “does” the role? What about the code that is checking if it “does” the role? I thought I tried all permutations. What a hassle.
There are subtle differences between Class::MOP and Perl 6′s MOP. Do not assume that they are the same. You will get bitten. On the other hand, it has a great shortcut! Perl 5: $class->meta->foo. Perl 6: $class^.foo.
Those are the major issues I noticed.
If you are interested, by the way, Log::Contextual has three major features that you might like. First, it returns the arguments you pass it, so you can use it in the middle of subroutine calls and whatnot. Next, it has convenience methods for automatically printing out stringified data structures. Nice! And lastly, (but arguably the whole point) is that it has a great interface based on lisp-y principles. I really should give it it’s own blog post at some point…
9 Mar
I just posted a workflow for Git on the Rakudo Wiki. Hopefully it works well and helps people use Git and work on Rakudo. Enjoy!
7 Mar
I like to make playlists. But I also reorganize my music something like once or twice a year. Because of that my playlists get broken as they are really just lists of filenames. This past summer I wrote some code in ruby that would find files with the same basename but ignore the directory structure, and reconstruct playlists from that. It worked perfectly except every now and then I would get a live version or two. This works because I have an sqlite database of all of my music thanks to amaroK.
Well, I decided that I would update the script so that I wouldn’t have those issues with live versions. I decided that I would have an intermediate filetype, which I would basically keep around forever. Announcing the FRU media playlist filetype! Actually not that exciting. Anyway, here are a couple scripts:
m3u2fru.pl6:
fru2m3u.pl6:
But the more important part, is the Ghetto module. Currently rakudo does not have any way to get the output of a command, but it can read from files, so we can fake it:
Obviously this is slow, bad in that it could possibly overwrite files, etc. It’s ghetto. But the idea is that later when we actually can do something like this without a ghetto solution it won’t be hard to fix your code.
I also thought it was fun to do a pipe-based solution. The way I had it set up before was something like this:
1 | ./plup.rb old.m3u new.m3u |
That’s alright, but I would usually look at the output to make sure it was right. Now I do this:
1 | cat old.m3u | ./m3u2fru.pl6 | ./fru2m3u.pl6 > new.m3u |
Sure it’s longer, but I can easily see the output at any point in the process. Furthermore, since I am using zsh (maybe bash can do this too, not sure) I can do this:
1 | cat old.m3u | ./m3u2fru.pl6 >new.fru | ./fru2m3u.pl6 > new.m3u |
So I can keep the intermediate results for next time!
28 Feb
This doesn’t really make rakudo interactive, it just gives you history, but that’s pretty nice!
1 | ledit ./perl6 |
ledit is in apt, so if you have ubuntu you can just install it with sudo aptitude install ledit. Very nice!