Archive

Archive for November, 2015

Perl 6 is a code generator

November 28, 2015 1 comment

While working on my post for this years Perl 6 Advent Calendar it occurred to me that Perl 6 is a code generator – mostly for Any.

class C {
    has $!var;

    multi name ($param) {}
}

Is turned into:

class C is Any {
    has $!var is default(Any);

    has multi method name ( Any $param is ro = Any --> Nil ) { return Nil }
}

Anonymous subs …

my &hidden = sub () {}

are quite wordy too:

my &hidden is default(Callable) = anon sub ( --> Nil ) { return Nil }

Nothing …

.say for 1,2,3:

tends to be turned into $_

$_.say for 1,2,3;

Control structures can hide operators

for 1, 'a' { .say when Str }

is a good bit shorter then

for 1, 'a' -> $_ { $_.say if $_ ~~ Str }

And stars …

subset Advent of Date where Date.new('2015-12-01') <= * <= Date.new('2015-12-25');

not only are turned into automatic variables, but also turn the stuff around them into a block.

subset Advent of Date where { Date.new('2015-12-01') <= $^a <= Date.new('2015-12-25') }
my Advent $my-post = Date.new('2015-12-02');
Categories: Uncategorized