Home > Uncategorized > Perl 6 is a code generator

Perl 6 is a code generator

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 --> Any ) { return Any }
}

Anonymous subs …

my &hidden = sub () {}

are quite wordy too:

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

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');
Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: