Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pop, push, reverse, sort, and splice on a multidimensional array

449 views
Skip to first unread message

Rod Adams

unread,
Mar 15, 2005, 3:22:13 AM3/15/05
to Perl6 Language List

my int @a is shape(Int ; Int) = (1..10 ; 2..100 :by(2) ; 4);

$x = pop @a
push @a, $x;
@b = sort @a;
# etc

I see two views to take with these cases.

1) flatten the array to one dimension, and act accordingly.

or

2) assume

my int @a is shape(Int ; Int);
my @a is Array of Array of int;

Mean exactly the same thing, as do

@a[3;4]
@a[3][4]

And then operate the Perl 5 way, where C<pop @a> would return an array ref.


#2 seems like the way to go, but I'm open to other suggestions.

I'm especially interested in hearing people's view on how C<splice>
should work with multi-dim arrays.

-- Rod Adams


Larry Wall

unread,
Mar 16, 2005, 12:45:40 PM3/16/05
to Perl6 Language List
On Tue, Mar 15, 2005 at 02:22:13AM -0600, Rod Adams wrote:
:
: my int @a is shape(Int ; Int) = (1..10 ; 2..100 :by(2) ; 4);

:
: $x = pop @a
: push @a, $x;
: @b = sort @a;
: # etc
:
: I see two views to take with these cases.
:
: 1) flatten the array to one dimension, and act accordingly.
:
: or
:
: 2) assume
:
: my int @a is shape(Int ; Int);
: my @a is Array of Array of int;
:
: Mean exactly the same thing, as do
:
: @a[3;4]
: @a[3][4]
:
: And then operate the Perl 5 way, where C<pop @a> would return an array ref.
:
:
: #2 seems like the way to go, but I'm open to other suggestions.

Seems right to me too. Could always reshape the array to one dimension
to get the other behavior, and since the array is reshaped, it wouldn't
end up "lopsided".

: I'm especially interested in hearing people's view on how C<splice>

: should work with multi-dim arrays.

I suppose that would depend on the dimensionality of the subscript. :-)

Larry

0 new messages