Re: RFC 196 (v1) More direct syntax for hashes
[email protected] (Dave Storrs) Mon, 11 Sep 2000 11:07:04 -0700 (PDT)
| Newsgroups | perl.perl6.language.data |
|---|---|
| Message-ID | <Pine.BSF.4.10.10009111056570.11946-100000@megazone23.bigpanda.com> |
On Thu, 7 Sep 2000, Michael G Schwern wrote: > 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. I'll weigh in with a "me too" on this. > > 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. I think my suggestion would be that we remove the other two features (which I doubt anyone uses all that often). However, if lots of people chime in with "no, no! We *must* have our reset as-is!" (or, more likely, if removing these features is too much of a pain for the p52p6 people), then here are some suggestions for alternate keywords: renew, restart, refresh, freshen, > > 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. I would go so far as to argue that the current behaviour is actually _bad_...if I want a list, I'll use a list. If I put things into a %hash, that means that I want THESE keys to be associated with THOSE values. The way sort currently works destroys those linkages. > 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. Again, "me too". Dave