4 ms·
Perl6 pointy block is just a synonym for a function. So below is exactly same as my pointy block example... my $x = sub ($a, $b) { $a + $b }; And typically
by draegtun 15y ago
Perl6 pointy block is just a synonym for a function. So below is exactly same as my pointy block example...
my $x = sub ($a, $b) { $a + $b };
And typically with Perl TIMTOWTDI :)
my $x = -> { $^a + $^b };
Personally I prefer the pointy block especially how it (visually) fits in with other Perl6 syntax constructs, for eg:
for 1..10 -> $odd, $even { say "odd $odd, even $even" }
- hippich 15y agoThank you for clarifying. Last example looks nice and make visual sense :) Could you point me somewhere or give a name for $^a/$^b? Want to find out how does it work :)
- draegtun 15y agoGenerically these are called twigils, ie. it has a second sigil. This second sigil describes what it does differently to single sigil variable. For eg. an asterisk denotes a contextual twigil variable... $*IN # equiv to STDIN in perl5 $*OUT # and STDOUT The ^ twigils denote placeholder variables. In Perl5 there is already implicily defined package variables called $a & $b so that you can do... sort { $a <=> $b } @array; In Perl 6 these are replaced with the ^ twigils so you can do... sort { $^a <=> $^b }, @array; or even... sort { $^x <=> $^y }, @array; ref: http://perlgeek.de/en/article/5-to-6#post_15 http://perlgeek.de/en/article/5-to-6#post_15 & http://perlcabal.org/syn/S06.html#Placeholder_variables http://perlcabal.org/syn/S06.html#Placeholder_variables BTW, Perl6 Placeholders have been ported back to Perl5 - https://metacpan.org/module/Perl6::Placeholders https://metacpan.org/module/Perl6::Placeholders