On Thu Dec 03 18:14:29 2015, alex.jakime...@gmail.com wrote:
> Code:
> my @a[3]; say @a.reverse
> 
> Result:
> Cannot reverse a fixed-dimension array
>   in block <unit> at -e:1
> 
> 
> It may be more complicated for multi-dimensional arrays, but reversing a
> 1-dimensional is rather straightforward. Therefore, it should probably
> throw a NYI warning.
> 
I decided to just implement it for 1-dimensional arrays. Left it as "no you 
cannot" for 2 dimensions and up, since it's not clear we'll settle on a 
semantics for that. Similar story for rotate, which now works on single-dim.

> But then it gets weirder:
> my @a[3] = <5 10 15>; say reverse(@a)
> 
> Result:
> [15 10 5]
> 
> Whoops! Seems like in this case there is a difference between 「reverse」 sub
> and 「.reverse」 method. I am not sure it if should be like so, I've always
> thought that both should behave almost identically.
> 
Fixed that one now, and along the way added a load of missing tests for sub 
forms of things on multi-dim arrays to make sure there weren't a bunch of other 
inconsistencies.

> Let's try the same thing with 「sort」:
> my @a[2;3] = (15,16,17), (4,5,6); say sort(@a)
> 
> Since 「reverse」 sub worked, we could expect 「sort」 to work as well (but
> notice that there are two dimensions now!).
> Here is the result:
> Cannot access 2 dimension array with 1 indices
>   in block <unit> at -e:1
> 
This is now fixed to produce (4,5,6,15,16,17) - that is, working on the leaves. 
Most things (like map) already worked nicely this way in both sub or method 
form, but sort does some odd things to cope with the first thing it gets being 
a Callable.

> Okay, that's LTA but it was somewhat expected. It is also how 「reverse」
> works with multidimensional arrays. Anyway, let's try the method:
> my @a[2;3] = (15,16,17), (4,5,6); say @a.sort
> 
> I am kinda expecting either NYI (if sorting a multidim array will ever make
> any sense) or “Cannot reverse a fixed-dimension array” error. Let's see.
> Result:
> (4 5 6 15 16 17)
> 
Which was correct already, and there's no a test to make sure we don't break it.

> It is just too inconsistent, I think.
> 
Yeah, the sub forms wanted a look, though most of the others were in good shape 
already.

> Possible solution:
> 1) Same behavior for subs and methods
> 2) NYI warning for all operations on 1-dimensional arrays if not
> implemented.
> 3) “Cannot reverse a multidimensional array” and similar errors for all
> operations with arrays that have more than 1 dimension.

Pretty much did that, though instead of 2 I just implemented the missing 
reverse/rotate operations. :-)

Tests in S09-multidim/methods.t and the newly-added S09-multidim/subs.t.

Reply via email to