What is the difference in contexts in nested and non-nested maps in Perl 6?

I have this bit of code. The first, not nested, mapdisplays some things, but the nested does not. I think I understand why the second does not work. The result is a lazy sequence, and Perl 6 collects the results. It's great. But not the first (not nested) maplazy in the same way? How does it output anything if I do nothing with the result of the map? That is, how is the first lazy? Does the receiver context automatically get where I have to explicitly point sink(or something) to the nested one? Anyway, I think Perl 6 will be able to figure this out for me.

my @array = (1, 2), (3, 4), ('a', 'b');

say "---On its own:";
my @item = 1, 2, 3;
@item.map: {
    say $_;
    };

say "---Inside another map:";
@array.map: {
    my @item = 1, 2, 3;
    @item.map: {
        say $_;
        }
    };

Here's the conclusion:

---On its own:
1
2
3
---Inside another map:

"map" "" Perl 6?. , , , .

eager, sink map:

say "---eager:";
@array.map: {
    my @item = 1, 2, 3;
    eager @item.map: {
        say $_;
        }
    };

say "---sink:";
@array.map: {
    my @item = 1, 2, 3;
    sink @item.map: {
        say $_;
        }
    };

say "---assignment:";
@array.map: {
    my @item = 1, 2, 3;
    @ = @item.map: {
        say $_;
        }
    };
+4
2

, , .. " ", 1. :

  • , sunk:

    • , .
    • (for, while .. 2) 3 .
    • , . 4
  • , , :

    • , , .

, .

map , sunk.

map , Seq.

map , , sunk, , Seq. ( say map, .)
Seq.

, 04, 664:

, sink, , . ( - , Perl, , , - "" .) , .

, . , ( , ), , , sink, .

sink , . , , , , , .


1) } , my @a = @b.map: { $_ + 1 } # whitespace/comment doesn't count
, .

2) map , , .

3) , , , , lazy for ^10 { .say } # as argument to a keyword expecting a single statement
(for ^10 { .say }) # inside an expression
. , .

. Rakudo, .

4) , , Rakudo, , .

+8

.map .Seq. , , Seq , , , .

, , .Seq :

my @array = (1, 2), (3, 4), ('a', 'b');
say "---Inside another map:";
say @array.map: {
    my @item = 1, 2, 3;
    @item.map: {
        say $_;
        }
    }
---Inside another map:
1
2
3
1
2
3
1
2
3
((True True True) (True True True) (True True True))

, : -)

. , , :

my @array = (1, 2), (3, 4), ('a', 'b');
say "---Inside another map:";
say @array.map: {
    my @item = 1, 2, 3;
    @item.map: {
        say $_;
        }
    42   # make sure ^^ map is sunk
    }
---Inside another map:
1
2
3
1
2
3
1
2
3
+5

Source: https://habr.com/ru/post/1667008/


All Articles