In Perl, a range within an array slice behaves as though the individual elements in the range had been specified with comma separators:

11:44 >perl -MData::Dump -we "my @c = 'a'..'z'; dd map { qq[<$_>] } @c +[6..9, 23, 25];" ("<g>", "<h>", "<i>", "<j>", "<x>", "<z>") 11:45 >

This is what I would expect. But in Raku, it seems that a range inside an array slice produces an additional layer of grouping:

11:45 >raku -v This is Rakudo version 2020.05.1 built on MoarVM version 2020.05 implementing Raku 6.d. 11:45 >raku -e "my @c = 'a'..'z'; @c[6..9, 23, 25].map( { qq[<$_>] } ) +.raku.put;" ("<g h i j>", "<x>", "<z>").Seq 11:46 >

AFAICT, the Raku documentation on subscripts doesn’t explain this. So, I have two questions:

  1. What is the cause of this (to me) strange behaviour? (Is it a feature or a bug?)
  2. How can I use ranges in Raku array slices to achieve the same result I get in Perl (i.e., no additional grouping)?

Thanks,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to [Raku] Ranges in array slices by Athanasius

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.