Welcome to yet another edition of the Perl 6 Weekly. With reports from the world of the SSSDR (Second System Syndrome Done Right)!
A New Face!
Thanks to the effort of a fine group of people, the home page of Perl 6 has gotten a face-lift. Some people like it, others dislike it. I guess there are fifty shades of (dis)like. Personally, I think it’s a great improvement.
Shifting And Scaling Of Ranges
You can now easily shift or scale Ranges:
say ^10 + 1; # 0..^10 -> 1..^11
say ^10 * 2; # 0..^10 -> 0..^20
say 10..^20 * 2; # 10..^20 -> 20..^40
I must say, I don’t regularly shift Ranges, but it is sure nice that Ranges now DWIM in this context. TimToady++
Function Composition Operator Added
TimToady++ implemented ∘ (U+2218 RING OPERATOR) as the Function Composition operator. There’s also a Texas version: o (U+006F LATIN SMALL LETTER O). Function composition is the pointwise application of one function to the result of another to produce a third function. So, how does that look in code? Suppose we have two subs:
sub double($x) { $x * 2 }
sub invert($x) { 1 / $x }
Suppose we want to create a new function that first doubles, and then inverts:
# &second o &first
my &double-invert = &invert o &double;
say double-invert(0.25); # 1 / (2 * 0.25) = 2
You will notice that the function to be executed first, is on the right hand side. So the other way around for first invert, then double is:
my &invert-double = &double o &invert;
say invert-double(0.25); # 2 * (1 / 0.25) = 8
Flattening Woes: Array.append/prepend
The One Argument flattening semantics of Array.push/unshift in the end caused more problems than that they were worth. Therefore, TimToady++ decided that Array.push/unshift will no longer flatten at all. This means that you can now say:
@a.push(@b.pop)
and not have to worry about the case where an Array would get popped off @b, which would then be flattened by the push on @a. You can now either flatten explicitely with .push, or use the new .append method:
@a.push(|@c);
@a.append(@c); # the same
The same applies to .unshift, with the new .prepend method:
@a.unshift(|@c);
@a.prepend(@c); # the same
This fallout of the Great List Refactor should be the last breaking change.
Type:D And Type:U On Variables And Attributes
FROGGS++ fixed a long standing bug report by implementing Definedness/Undefinedness modifiers on the Type definition of variables and attributes. With this you can e.g. ensure that a variable can only contain defined values: it will throw an exception if an undefined value is assigned to it. So how does this look?
my Int:D $a = 42; # ok
my Int:D $b; # must be defined, so 0
say $b; # 0
$b = Int;
# Type check failed in assignment to $b;
expected Int:D but got Int
Another nice addition that will allow you to write more robust code!
Noticeable Features, Fixes And Improvements
- Doing an exit() will no longer break profiling
- Bag/Mix are now really immutable (last loopholes closed)
- BagHash/MixHash now only accept Int/Real values
- Pair.freeze will make the value of a Pair immutable
- Many speed improvements, specifically of iterators
Blog Posts
- What Makes Good Documentation?: discussion initiated by David Adler
- Those Weeks – Much Progress by Jonathan Worthington
- 5 Tips For Writing Better Perl 6 Modules by Nick Logan
- Vagrant Perl Development Environment v1.1.0 released by Gabor Szabo
- Three Types Of Macros: discussion initiated by Carl Mäsak
- Things That Won’t Make It Into 6.Christmas: discussion initiated by Jonathan Worthington
Ecosystem Additions
- IO::Blob by Taiki Kawakami
- HTTP::Tinyish by Shoichi Kaji
- HTTP::Parser by Tokuhiro Matsuno
- HTTP::Server::Tiny by Tokuhiro Matsuno
- Getopt::Tiny by Tokuhiro Matsuno
Winding down again
Another Perl 6 Weekly made it to your screen. Tune in next week for more!
Thank you! I really missed these when they weren’t coming…