Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Perl6's future

Name: Anonymous 2011-02-16 12:29

Hai gais

What do you think will happen to perl6 ???

1) Will have the same fate as Haskell...
2) Python3's snake will eat the Perl6 butterfly
3) Only ParrotVM will be succesfull
4) Perl6 will become the new Java
5) faggot

Name: Anonymous 2011-02-17 9:02

>>35
I'm not by any means a proficient Perl programmer, so take it with a grain of salt.

$_ is like a shortcut for an unary anonymous function:


>(1,2,3).map: sub ($x) {$x + 2};
3 4 5

sub ($x) {$x + 2}; -> sub ($_) {$_ + 2}; -> {$_ + 2};

>(1,2,3).map: {$_ + 2};
3 4 5


{$_} for 0..*; is just an iteration:

>{say $_} for 0..10;
0
1
2
3
4
5
6
7
8
9
10


@g[* - 1] is a ``reverse" indexing:

>my @g = 1,2,3,4;
1 2 3 4
>@g[* - 1];
4
>@g[* - 2];
3


So in line 5 we are doing a lookup on the %set hash and incrementing values:


>my %set = {1 => 1};
1    1

>++%set<1>;
2

>%set
1    2


Line 6 is simple. first takes a block and an array or a sequence and returns the first element from the sequence for which the block evaluates to true:

>first {$_ == 10}, 3..*;
10

>first {$_ % 2 == 0}, 3..*;
4


%set.exists($_) tests if hash has the given key. ! is negation, so first { !%set.exists($_) }, 0..*; means return the first number from the 0..* sequence that is not the key in the %set hash.

Hope it was clear.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List