Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.splice insists on flattening the replacement #5500

Open
DarthGandalf opened this issue Dec 18, 2023 · 1 comment
Open

Array.splice insists on flattening the replacement #5500

DarthGandalf opened this issue Dec 18, 2023 · 1 comment
Labels
consistency CORE.setting Things broken in the CORE.setting

Comments

@DarthGandalf
Copy link

The Problem

I have a 2d array (array of arrays), and I want to insert a new row to it.

my @map = [[11, 12], [31,32]];
my @newrow = [21, 22];
@map.splice(1, 0, @newrow);

Expected Behavior

I want @map to look like this:

[
    [11, 12],
    [21, 22],
    [31, 32]
]

Actual Behavior

@map will now look like this:

[
    [11, 12],
    21,
    22,
    [31, 32]
]

I tried to pass [[[[@newrow]]]] to .splice(), tried to pass $@newrow, without any difference. The only workaround I found is this:

@map.splice(1, 0, 'dummy');
@map[1] = @newrow;

Environment

  • Operating system: Gentoo Linux, amd64
  • Compiler version (rakudo -v or raku -v): v2023.10
@ab5tract ab5tract added consistency CORE.setting Things broken in the CORE.setting labels Jan 22, 2024
@ab5tract
Copy link
Collaborator

ab5tract commented Mar 23, 2024

It took a minute (longer than it should have, in retrospect) but I think I have a way to resolve this without breaking any existing splice contracts.

my @a = [1, 2, 3];
@a.splice(1, 1, [2, 2]) :preserve;
dd @a; # [1, [2, 2], 3

Note that :preserve is just the best I've been able to come up with so far. Suggestions welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consistency CORE.setting Things broken in the CORE.setting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants