5

In raku documentation for class Slip (https://docs.raku.org/type/Slip) and also in "Lists, sequences, and arrays" documentation (slips section: https://docs.raku.org/language/list), it is stated that "slip", "Slip (method)" and "| (prefix)" can be used to create slips but they behave slightly "different".

The thing is that I've tried to confirm the above statement but with disappointing results.

I run the following tests to find out the differences:

my $l = (1, 2, 3);

say (0, slip($l, 4)).perl;
say (0, ($l, 4).Slip).perl;
say (0, |($l, 4)).perl;

say '------------------------------';

say (slip($l, 4)).perl;
say (($l, 4).Slip).perl;
say (|($l, 4)).perl;

say '------------------------------';

say (0, slip($l)).perl;
say (0, ($l).Slip).perl;
say (0, |($l)).perl;

say '------------------------------';

say (0, slip $l).perl;
say (0, $l.Slip).perl;
say (0, |$l).perl;

say '------------------------------';

say (slip $l).perl;
say ($l.Slip).perl;
say (|$l).perl;

and the results are the same for all three of them:

(0, $(1, 2, 3), 4)
(0, $(1, 2, 3), 4)
(0, $(1, 2, 3), 4)
------------------------------
slip($(1, 2, 3), 4)
slip($(1, 2, 3), 4)
slip($(1, 2, 3), 4)
------------------------------
(0, 1, 2, 3)
(0, 1, 2, 3)
(0, 1, 2, 3)
------------------------------
(0, 1, 2, 3)
(0, 1, 2, 3)
(0, 1, 2, 3)
------------------------------
slip(1, 2, 3)
slip(1, 2, 3)
slip(1, 2, 3)

Is there a catch or is it a documentation bug?

jakar
  • 1,701
  • 5
  • 14

1 Answers1

4

Just a little further down the docs you find an example of the ( a? ) difference:

Please note that prefix:<|> will also apply parameters in a slippy manner to a routine call. It does not forward a Slip to the called routine, that includes return and take.

my \l = gather for 1..10 -> $a, $b { take |($a, $b) }; say l.perl;
# OUTPUT: «((1, 2), (3, 4), (5, 6), (7, 8), (9, 10)).Seq
my \m= gather for 1..10 -> $a, $b { take ($a, $b).Slip }; say m.perl;
# OUTPUT: «(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).Seq
Holli
  • 5,072
  • 10
  • 27
  • Yes you are right about that behaviour but my worries are that the documentation states that: "Another way to make a Slip is with the | prefix operator. Note that this has a tighter precedence than the comma, so it only affects a single value, but unlike the above options, it will break Scalars." This is by NO means the correct behaviour!!! – jakar Jan 14 '20 at 16:35
  • Check that out: say (1, slip($(2, 3)), 4) eqv (1, 2, 3, 4); # OUTPUT: «False␤» – jakar Jan 14 '20 at 16:38
  • The slip routine breaks ALSO scalars ! – jakar Jan 14 '20 at 16:39
  • That code line (with the expected output) is from the documentation! The answer is indeed "True" !!! – jakar Jan 14 '20 at 17:02
  • 3
    Good catch. This is indeed a bug in the documentation. Liz has just fixed it, the change should come online soon. – Holli Jan 14 '20 at 18:19
  • 1
    Also the statement: [ say (0, slip $l).perl; # says (0, $(1, 2, 3)), $l does not break apart ] in Slip documentation is NOT true. The proper result is (0, 1, 2, 3) – jakar Jan 15 '20 at 13:21