On Wed, Sep 06, 2000 at 06:40:10PM -0000, Perl6 RFC Librarian wrote:
> C<scalar(%hash)> should return what C<scalar(keys %hash)> currently
> returns.
Good.
> C<reset %hash> should reset the hash iterator, instead of calling
> C<keys> or C<values> as is currently the case.
Sounds good, except the name. reset() already does something.
Currently, reset() is for clearing large swaths of global variables (a
dubious feature) and for reseting ?pattern? searches. Two weird
features crammed into one keyword. Shoving a third in doesn't seem
pleasent.
Either think up a better keyword, or remove those two crufty features.
> The parser should special-case the variations of C<sort %hash> so
> that it returns the keys and value, calling the comparison function
> for keys.
I'm trying to think of a common case where I'd want sort() to treat a
%hash like a list (as it currently does) but I can't really think of
one.
> Proposal 3 is to have the parser identify C<sort %hash> and its
> variations, and automatically turn it into C<sort keys %hash>.
> I'd like to be able to say:
>
> foreach ($k,$v) (sort %hash) { ... }
>
> This would be equivalent to:
>
> foreach ($k,$v) (map { $_ => $hash{$_}
> sort
> keys %hash)
> { ... }
What you proposed and what you put in your example doesn't quite play
out. C<sort keys %hash> returns just the sorted keys of %hash, but
your foreach example implies that both keys and values would be
returned, sorted by key. Both would be useful.
I'd edge towards the latter because the former is simple enough to
reproduce (just explicitly say C<sort keys %hash>) and its use is
mostly when you want to iterate over the keys of a sorted hash, which
would largely be eliminated if your proposal returned a 'sorted' hash.
--
Michael G Schwern http://www.pobox.com/~schwern/ [EMAIL PROTECTED]
Just Another Stupid Consultant Perl6 Kwalitee Ashuranse
But why? It's such a well designed cesspool of C++ code. Why wouldn't
you want to hack mozilla?
-- Ziggy