On Mon, Mar 26, 2001 at 03:36:08PM -0500, Dan Sugalski wrote:
>>> because that would require the PSI::ESP module which isn't working
>>> yet.
>> Not at all.  Simon's example looks like a simple case of memoization.
>> The cache only needs to be maintained for the duration of the sort,
>> and it alleviates the need for complicated map{} operations.
> The only issue there is whether memoization is appropriate. It could be 
> argued that it isn't (it certainly isn't with perl 5) though I for one 

I realize that memoization isn't something you want to do on functions
that may return different results with the same input. However I'm a bit
curious of when these functions are useful in sort(), and in particular
when you _really_ need every comparison to be unmemoized.

  sort {rand($a) <=> rand($b)} @nums;

Is it really desirable to get different results from rand() on every
single comparison?

Will the above generate a more random list than this?

  map  { $_->[0] } 
  sort { $a->[1] <=> $b->[1] }
  map  { [$_, rand($_)] } 
  @nums;

-- 
Trond Michelsen

Reply via email to