Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created November 16, 2016 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizmat/916dd334cce318b3ae0594afbe537214 to your computer and use it in GitHub Desktop.
Save lizmat/916dd334cce318b3ae0594afbe537214 to your computer and use it in GitHub Desktop.
nqp::atpos works differently between normal and shaped arrays
use nqp;
sub reverse(\a,\b) {
my int $elems = a.elems max b.elems;
my int $last = $elems - 1;
my Mu $a := nqp::getattr(a,List,'$!reified');
my Mu $b := nqp::getattr(b,List,'$!reified');
for ^$elems -> int $i {
nqp::bindpos(
$b,
nqp::sub_i($last,$i),
nqp::atpos($a,$i) # for normal array
# nqp::decont(nqp::atpos($a,$i)) # for shaped array
)
}
b
}
my @a[5] = ^5;
my @b[5] = ^5;
@a = reverse(@a,@b);
dd @a, @b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment