/ Perl6

Perl6 Advent Calendar 2015

This is the Christmas I have been waiting for for 15 years! Ever seance I got word that there was to be a major redesign of the Perl programming language, I have been interested in what Perl would become.

For me Perl was a powerful enough programming language for the type of problems I was trying to solve. I have worked with others, but they were ether too complicated or really too simple. Perl was right there in the sweet spot.

I started using Perl6 around 2007, and have seen it progress immensely, becoming more stable, quicker, and useful, year after year. The running joke with Perl6 was that it was going to be released on Christmas. But for years that Christmas never came.

However according to Larry Wall himself in a presentation he gave back in October, Perl6 will be released THIS Christmas! Like I said before, I have been using the pre-release versions of Perl6 seance 2007 and have watched it grow more useful. I would say the last 3 years Perl6 has mostly been ready for everyday use.

Here is the announcement Larry Wall made regarding Perl6: (kinda long)

Every year in December https://perl6advent.wordpress.com/ will do a sorts of Advent Calendar related to the Perl6 programming language. I have learned much from the examples posted there and I'm really grateful for their efforts. I'm sure they have helped many people in learning this new Perl6 thing. This year I expect the Perl6 Advent Calendar will be outstanding! And from what I have read so far I'm really excited.

The remainder of this post I'll talk breifly about what was discussed or what I found interesting on the 2015 Advent Calendar. There is already 2 entries in this Perl6 Advent season. The first post mostly goes over some housekeeping and relates the recent events in the world of Perl6.

The second post reviles something new, Proxies. (new at least for me.) The theory behind Perl6 Proxies is to have a variable, and have a bit of code executed every time that variable is retrieved or stored. As this was a new concept to me I had to look it up. So to the Perl6 documentation on Proxies I went.

So according to the spec:
A Proxy is an object that allows you to execute whenever a value is retrieved from a container (FETCH) or when it is set (STORE).

Now some code to show a container:

sub double() is rw {
    my $storage = 0;
    Proxy.new(
        FETCH => method ()     { $storage },
        STORE => method ($new) { $storage = 2 * $new }
    )
 }

And some code to make use of the above container:

 my $doubled := double();
 $doubled = 4;
 say $doubled;       # 8

So first we create a new container variable called $doubled with the line my $doubled := double();

Next we set a value with the line: $doubled = 4; When we do this, the code in the STORE block of the double() container is run. In this case it takes the value of 4 and multiplies it by 2, then saves it in the variable $storage

Finally we retrieve the current value of the container with the line: say $doubled; This will run the code in the FETCH block, in this case we just return the current value stored in $storage

I see this as a really useful way to ensure some process is completed every time a proxied container is ether set or retrieved. It has me thinking how I could make use of this nice little gem in future projects....