factor icon indicating copy to clipboard operation
factor copied to clipboard

When called on an immutable seq, suffix! doesn't throw the correct error

Open LeoMehraban opened this issue 3 months ago • 7 comments

I'd expect the code

IN: scratchpad { } "a" suffix!

to throw an immutable error. Instead, it throws a sequence out of bounds error:

T{ bounds-error { index 0 } { seq { } } }

I've tested this for arrays and strings, so it's probably all immutable sequences that are effected

LeoMehraban avatar Sep 25 '25 23:09 LeoMehraban

Well, it's not an immutable sequence:

IN: scratchpad { } immutable? .
f

mrjbq7 avatar Sep 30 '25 18:09 mrjbq7

Perhaps you're thinking we need like a not-growable? mixin?

mrjbq7 avatar Sep 30 '25 18:09 mrjbq7

Wait, arrays are mutable? I thought the whole difference between arrays and vectors are that vectors are mutable and arrays aren't

LeoMehraban avatar Oct 01 '25 01:10 LeoMehraban

Either way, an out of bounds error isn't very helpful in this context

LeoMehraban avatar Oct 01 '25 01:10 LeoMehraban

Immutable means the contents can’t be changed.

Message ID: @.***>

mrjbq7 avatar Oct 01 '25 01:10 mrjbq7

What error seems more appropriate?

It’s saying that it can’t set a value at index 0.

mrjbq7 avatar Oct 01 '25 01:10 mrjbq7

Vectors are growable and arrays are not.

mrjbq7 avatar Oct 01 '25 01:10 mrjbq7