Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do array indices need to be native ints?

Tags:

raku

I am trying to obtain the umptieth element of an array:

my @lazy-array = lazy 1, 11, 121 ... 10**100;
say @lazy-array[10**50];

This yields

Cannot unbox 167 bit wide bigint into native integer

Same problem if I assign it to a variable. This does not seem to be reflected in the documentation, and wonder if it's a feature or a bug. Also, what would be the correct way of acessing those positions (other than iterating)

like image 687
jjmerelo Avatar asked Apr 04 '20 16:04

jjmerelo


1 Answers

In the current implementation in Raku, which is based on NQP, array indexes have a maximum of 63 bits (at least on 64bit builds).

use nqp;
my $l := nqp::list;
dd nqp::atpos($l,0x7fff_ffff_ffff_ffff);  # Mu
dd nqp::atpos($l,0x7fff_ffff_ffff_ffff + 1);
# Cannot unbox 64 bit wide bigint into native integer

I would not consider it a feature or a bug, but a limitation of the current implementation.

Please note that you could use Array::Sparse if you want to use larger indexes.

like image 183
Elizabeth Mattijsen Avatar answered Sep 18 '22 12:09

Elizabeth Mattijsen