Re: RFC 196 (v1) More direct syntax for hashes

2000-09-07 Thread Michael G Schwern

On Wed, Sep 06, 2000 at 06:40:10PM -, Perl6 RFC Librarian wrote:
 Cscalar(%hash) should return what Cscalar(keys %hash) currently
 returns.

Good.


 Creset %hash should reset the hash iterator, instead of calling
 Ckeys or Cvalues 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 Csort %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 Csort %hash and its
 variations, and automatically turn it into Csort 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.  Csort 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 Csort 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



Re: RFC 196 (v1) More direct syntax for hashes

2000-09-07 Thread Nathan Torkington

Michael G Schwern writes:
  Creset %hash should reset the hash iterator, instead of calling
  Ckeys or Cvalues 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.

I was expecting those two crufty features to be removed.  If they
aren't, a third won't hurt.

  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.  Csort 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.  

That's what the map is for.  (modulo syntax error in the map :-)

Nat



Re: RFC 196 (v1) More direct syntax for hashes

2000-09-07 Thread Michael G Schwern

On Thu, Sep 07, 2000 at 10:22:17PM -0600, Nathan Torkington wrote:
 Michael G Schwern writes:
 I was expecting those two crufty features to be removed.  If they
 aren't, a third won't hurt.

Might want to add this assumption to the RFC.  Or perhaps another RFC
to junk reset()'s current meaning.


   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.  Csort 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.  
 
 That's what the map is for.  (modulo syntax error in the map :-)

Okay, the example says on thing and the text of the proposal says
another.

So you're proposing that Csort %hash act like Cmap { $_ =
$hash{$_} } sort keys %hash?  I can live with that.  Just clear it up
in the RFC.

-- 

Michael G Schwern  http://www.pobox.com/~schwern/  [EMAIL PROTECTED]
Just Another Stupid Consultant  Perl6 Kwalitee Ashuranse
GuRuThuG make a channel called Perl, and infest it with joking and
funit doesnt make alot of sense.



Re: RFC 196 (v1) More direct syntax for hashes

2000-09-07 Thread Nathan Torkington

Michael G Schwern writes:
 Okay, the example says on thing and the text of the proposal says
 another.

Sorry, I thought you were talking about a different section of code.
I'll resubmit tomorrow.

 So you're proposing that Csort %hash act like Cmap { $_ =
 $hash{$_} } sort keys %hash?  I can live with that.  Just clear it up
 in the RFC.

That's what I'm saying.

Nat