On Thursday, December 12, 2002, at 02:40  PM, Smylers wrote:
What if the thing being C<sort>ed (or whatever) is not an array but a
list?

  @out = sort $scalar, @array, result_of_calling_function($param);

Would the list have to be stored in an array before it could be sorted?
I hope and expect that there is sufficient magic to treat a list as an Array wherever necessary, such that Array method calls should be allowed on any literal or C<return>ed list.

( $scalar, @array, foo() ).sort {...}; # [1]

my @a = ( $scalar, @array, foo() ); # [2]
@a.sort {...};

If we kept the current map syntax, the same should be true:

sort {...} $scalar, @array, foo(); # [1]

my @a = ( $scalar, @array, foo() ); # [2]
sort {...} @a;

Or if we can come up with a reverse-dot syntax that treats C<sort> as a method of Array, and not a reserved keyword:

sort { ... } <- $scalar, @array, foo(); # [1]

my @a = ( $scalar, @array, foo() ); # [2]
sort {...} <- @a;

In each case, [1] should be marginally more efficient than [2], because it's doing less.

Same magic for hashes, too. And maybe even for references upon arrays/hashes:

(1,2,3,4,5).reverse; # returns (5,4,3,2,1)
[1,2,3,4,5].reverse; # returns [5,4,3,2,1]

But note:

@a.reverse;
@a .= reverse; # these two might mean different things?

my @a = (1,2,3,4,5);
@a.reverse; # OK

my $a = [1,2,3,4,5];
$a.reverse; # but this might be problematic

That last line would be OK only if the C<Ref> type either didn't have any methods of it's own (unlikely), or if C<Ref> knew to look in the methods of the referred-to obj if the method was not part of C<Ref> itself.

MikeL

Reply via email to