Sunday, August 30, 2009

meta: no time to write what I want! badges! brokeness!

Well, it has been eight days and I am pushing the limit of staying in the competition (or at least not resetting the clock). There are a few things I want to write, but don't have the time to pay attention to right now. Quick list of posts I want to write so I don't forget them:
  • simple parsing
  • shared memory (IPC and persistence)
  • dealing with Unicode combining characters (needs more research)
In other news, the Perl Ironman Badges are up finally, but sadly my name seems to be breaking it. I can find a Chas and an Owens badge, but not a Chas. Owens badge. Also, I am showing up as a paperman in both which is either a bug in its calculation or mine.

Saturday, August 22, 2009

Projects in progress as of 2009-08-22

Unicode::Digits (GitHub, CPAN)

A test is failing on Perl 5.8. This is due to the test using a character that is a digit in Perl 5.10, but not in Perl 5.8. I need to fix this problem.

I also want to add a function that will return a regex that can match a given digit or digits (i.e. it should be able to match "42", "𝟜𝟚", or "᠔᠒"), but I am still not certain how the interface should work. For instance, should it only allow single digits (forcing the user to build more complicated regexes?
my $one = digit_one();
Should it take a string and replace the digits and character classes with the expanded character classes?
my $re = digit_regex "This matches 42";
Should it be OO based and let you chose specific sets of digits?
my $ud = Unicode::Digit->new(
"ASCII", #special case, "" looks stupid
my $re = $ud->digit_regex("[1-3]");
I am leaning toward the last one. And I am leaning toward only allowing a small subset of regex-like syntax (basically numbers and character classes containing numbers or ranges only).

autobox::dump (GitHub, CPAN)

I need to finish extending it to handle YAML and Data::Dump::Streamer.

Term::Throbber (not published anywhere)

I saw Term::Spinner and hubris struck me. First I patched Term::Spinner to be able to handle arbitrary sized frames, but then I found my self annoyed by the interface, terminology, and use of vanilla Moose in Term::Spinner, so I have written my own MooseX::Declare based version. I haven't written any tests for it yet. Once the tests are written and passing (and I am satisfied with the interface) I will put it up on GitHub and CPAN.

perlopref (GitHub)

Lots more work needs to be done before this is finished. My goal of adding at least one operator a day failed. I need to recommit myself to getting it done.

warnin's (GitHub)

I think warnin's is going to die an ignoble death. The talk of removing ' as a package separator combined with my own apathy means it is unlikely for anything new to be done with it.

Sunday, August 16, 2009

project: Anouncing perlopref

In my last post I discussed the need for a perlopref document and even posted a portion of the version I am working on. I got some positive feedback and no negative feedback, so I have created a GitHub repository and uploaded what I currently have to it. There has already been one fork that fixed some of my POD stupidity.

If you want to help, just fork my repository, file an issue against my repository claiming an operator, make your change, and then submit a pull request. Note: not all of the operators are currently listed in the file (e.g. the filetest operators and the quote-like operators are not yet listed).

There is no guarantee that this document will make it into a release of Perl, but at the very least I will be creating a CPAN distribution for it.

Saturday, August 15, 2009

adventures in ignorance: modulo operator

Recently on the Perl Beginners mailing list I saw a new user having difficulty understanding the documentation for ||=. My first reaction was "hey, it is spelled out in straight forward English, ||= is like += but using || instead of +, go look up || and you there you are." Then I starting thinking about it. As a reference, perlop is less than optimal. Many of the operators are discussed tangentially (like ||=) and many others are never mentioned (like the file test operators, which I know are documented in perlfunc, but they look like operators to me). This has inspired me to write perlopref. I haven't socialized this anywhere but the Perl Beginners mailing list and here because I want to make sure the idea is viable first. So far it seems to be working for me, and I am learning a lot of the nooks and crannies I had been able to ignore in the past.

One of these nooks (or is it a cranny?) is the modulo operator (%), or more specifically what happens with negative numbers. I had never bother to consider how negative numbers would affect modulo. I found the text in perlop to be very opaque. Every time I tried to read it I found my eyes slipping down the page trying to get away, and I know what modulo does. I don't know if it is me, or the text, but I can't imagine trying to understand what the text was saying if I didn't already know what it did. Here is the part that covers modulo in my first draft of perlopref.pod (the pod is available here)

X % Y

This is the modulo operator. It computes the remainder of X divided by Y. The remainder is affect by the type of the numbers and whether they are positive or negative.

Given integer operands X and Y: If Y is positive, then X % Y is X minus the largest multiple of Y less than or equal to X. If Y is negative, then X % Y is X minus the smallest multiple of Y that is not less than X (i.e. the result will be less than or equal to zero). To illustrate this, here are the results of modding -9 through 9 with 4:
when X is     -9 -8 -7 -6 -5 -4 -3 -2 -1  0  1  2  3  4  5  6  7  8  9
the result is 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1
And here is -9 through 9 modded with -4:
when X is     -9 -8 -7 -6 -5 -4 -3 -2 -1  0  1  2  3  4  5  6  7  8  9
the result is -1 0 -3 -2 -1 0 -3 -2 -1 0 -3 -2 -1 0 -3 -2 -1 0 -3
From this we can see a positive Y constrains X to a range from 0 to (Y - 1) that wraps around and a negative Y constrains X to a range from (Y + 1) to 0.

When Y is a floating point number whose absolute value is in the range of 0 to (UV_MAX + 1) (where UV_MAX is the maximum of the unsigned integer type) X and Y are truncated to integers. If the absolute value of Y is larger than (UV_MAX + 1) then the formula (X - I * Y) (where I is a certain integer that makes the result have the same sign as Y). For example, on 32-bit systems 4.5 % (2 ** 32 - 1) is 4, but 4.5 % 2 ** 32 is 4.5.

Note: when the integer pragma is in scope % gives you direct access to the modulo operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster.

my $odd = $x % 2; #$odd is 1 when $x is odd and 0 when $x is even
my $hour = ($hour + 1) % 24; # 23 (11pm) plus 1 hour is 0 (12am).

Sunday, August 9, 2009

meta: how I am keeping myself motivated part 2

oylenshpeegul asked on my last meta post about whether or not Google Analytics tracks RSS feeds. It does not; however, another Google service does: FeedBurner.The data for clicks matches up pretty well against what Analytics is saying. I find the interface to Analytics nicer than FeedBurner, but FeedBurner has statistics about how the feed is being used. I will probably visit both now.

Friday, August 7, 2009

error building Perl 5.10.1-RC1

So, if you are trying to compile 5.10.1-RC1 and it throws the error "Can't locate unicore/ in @INC", you most likely have the PERL_UNICODE environment variable set. A quick
will fix the problem (or, at least, it did for me).

meta: how I am keeping myself motivated

So, I have had blogs in the past, but I have never managed to stay interested in them. This time is different and the reason is simple: data. I turned on Google Analytics and I visit the graphs once or twice a day:

Just this little reassurance that people are looking at what I am writing is keeping the blog in my mind. Because it is in my mind, when something happens (like, say, my next article about my stupidity using split and ord) I remember to start writing stuff down.

Tuesday, August 4, 2009

I am living in the future

I saw an interesting post today on the Perl Iron Man feed about the fact that /\Q foo \E/x turns into /\ foo\ / despite the /x option being set. This is not so remarkable because of the content (which was interesting and unexpected, although I am not sure what I would have expected to happen there), but rather because the post was in Japanese and I can't read Japanese. With machine translation I was able to understand what he/she was driving at. Truly, we are living in the future.