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 --> 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
Comments (0)
Trackbacks (1)
Leave a comment
Trackback
-
June 13, 2021 at 16:42Teaching on a waterbed | Playing Perl 6␛b6xA Raku