in reply to [Raku] Ranges in array slices

Not a bug, just a misunderstanding about how Iterables (Lists, Ranges, etc) work in Raku: Namely they do not automatically flatten.
.WHAT.say for 6..9, 23, 25; # (Range) (Int) (Int) .WHAT.say for flat 6..9, 23, 25; # (Int) (Int) (Int) (Int) (Int) (Int)


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re^2: [Raku] Ranges in array slices
by Athanasius (Archbishop) on Jun 01, 2021 at 06:26 UTC

    Hello holli,

    Thanks, that’s brilliant!

    Note for my fellow Raku-challenged monks: My first thought on seeing holli’s code was that flat was taking the range 6..9 as its argument. But, of course, the argument to flat here is the whole comma-separated list: 6..9, 23, 25. So the following constructs both solve my problem:

    16:21 >raku -e "my @c = 'a'..'z'; @c[flat 6..9, 23, 25].map( { qq[<$_> +] } ).raku.put;" ("<g>", "<h>", "<i>", "<j>", "<x>", "<z>").Seq 16:21 >raku -e "my @c = 'a'..'z'; @c[ (6..9, 23, 25).flat ].map( { qq[ +<$_>] } ).raku.put;" ("<g>", "<h>", "<i>", "<j>", "<x>", "<z>").Seq 16:22 >

    Thanks again,

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